ekg2
Struktury danych | Definicje | Definicje typów | Funkcje

Dokumentacja pliku ekg/dynstuff.h

Idź do kodu źródłowego tego pliku.

Struktury danych

struct  list
struct  string
struct  private_data_s

Definicje

#define LIST_ADD_COMPARE(x, type)   int x(const type data1, const type data2)
#define LIST_ADD_SORTED(list, data, comp)   list_add_sorted(list, data, (void *) comp)
#define LIST_ADD_SORTED2(list, data, comp)   list_add_sorted3((list_t *) (void *) list, (list_t) data, (void *) comp)
#define LIST_ADD_BEGINNING2(list, data)   list_add_beginning3((list_t *) (void *) list, (list_t) data)
#define LIST_ADD2(list, data)   list_add3((list_t *) (void *) list, (list_t) data)
#define LIST_COUNT2(list)   list_count((list_t) list)
#define LIST_GET_NTH2(list, id)   list_get_nth3((list_t) list, id)
#define LIST_RESORT(list, comp)   list_resort(list, (void *) comp)
#define LIST_RESORT2(list, comp)   list_resort3((list_t *) (void *) list, (void *) comp)
#define LIST_REMOVE(list, data, func)   list_remove2(list, data, (void *) func)
#define LIST_REMOVE2(list, elem, func)   list_remove3((list_t *) (void *) list, (list_t) elem, (void *) func)
#define LIST_UNLINK2(list, elem)   list_unlink3((list_t *) (void *) list, (list_t) elem)
#define LIST_FREE_ITEM(x, type)   void x(type data)
#define LIST_DESTROY(list, func)   list_destroy2(list, (void *) func)
#define LIST_DESTROY2(list, func)   list_destroy3((list_t) list, (void *) func)

Definicje typów

typedef struct listlist_t
typedef struct stringstring_t
typedef struct private_data_s private_data_t

Funkcje

void * list_add (list_t *list, void *data)
void * list_add_beginning (list_t *list, void *data)
void * list_add_sorted (list_t *list, void *data, int(*comparision)(void *, void *))
void * list_add3 (list_t *list, list_t new_)
void * list_add_beginning3 (list_t *list, list_t new_)
void * list_add_sorted3 (list_t *list, list_t new_, int(*comparision)(void *, void *))
int list_count (list_t list)
void * list_get_nth (list_t list, int id)
void * list_get_nth3 (list_t list, int id)
void list_resort (list_t *list, int(*comparision)(void *, void *))
void list_resort3 (list_t *list, int(*comparision)(void *, void *))
int list_remove (list_t *list, void *data, int free_data)
int list_remove2 (list_t *list, void *data, void(*func)(void *))
void * list_remove3 (list_t *list, list_t elem, void(*func)(list_t))
void * list_remove3i (list_t *list, list_t elem, void(*func)(list_t data))
void * list_unlink3 (list_t *list, list_t elem)
int list_destroy (list_t list, int free_data)
int list_destroy2 (list_t list, void(*func)(void *))
int list_destroy3 (list_t list, void(*func)(void *))
void list_cleanup (list_t *list)
int list_remove_safe (list_t *list, void *data, int free_data)
string_t string_init (const char *str)
int string_append (string_t s, const char *str)
int string_append_n (string_t s, const char *str, int count)
int string_append_c (string_t s, char ch)
int string_append_raw (string_t s, const char *str, int count)
int string_append_format (string_t s, const char *format,...)
void string_insert (string_t s, int index, const char *str)
void string_insert_n (string_t s, int index, const char *str, int count)
void string_remove (string_t s, int count)
void string_clear (string_t s)
char * string_free (string_t s, int free_string)
char ** array_make (const char *string, const char *sep, int max, int trim, int quotes)
char * array_join (char **array, const char *sep)
char * array_join_count (char **array, const char *sep, int count)
int array_add (char ***array, char *string)
int array_add_check (char ***array, char *string, int casesensitive)
int array_count (char **array)
int array_contains (char **array, const char *string, int casesensitive)
int array_item_contains (char **array, const char *string, int casesensitive)
char * array_shift (char ***array)
void array_free (char **array)
void array_free_count (char **array, int count)
const char * itoa (long int i)
const char * cssfind (const char *haystack, const char *needle, const char sep, int caseinsensitive)
char * escape (const char *src)
char * unescape (const char *src)
int private_item_get_safe (private_data_t **data, const char *item_name, char **result)
const char * private_item_get (private_data_t **data, const char *item_name)
int private_item_get_int_safe (private_data_t **data, const char *item_name, int *result)
int private_item_get_int (private_data_t **data, const char *item_name)
void private_item_set (private_data_t **data, const char *item_name, const char *value)
void private_item_set_int (private_data_t **data, const char *item_name, int value)
void private_items_destroy (private_data_t **data)

Dokumentacja definicji

#define LIST_ADD2 (   list,
  data 
)    list_add3((list_t *) (void *) list, (list_t) data)
#define LIST_ADD_BEGINNING2 (   list,
  data 
)    list_add_beginning3((list_t *) (void *) list, (list_t) data)
#define LIST_ADD_COMPARE (   x,
  type 
)    int x(const type data1, const type data2)
#define LIST_ADD_SORTED (   list,
  data,
  comp 
)    list_add_sorted(list, data, (void *) comp)
#define LIST_ADD_SORTED2 (   list,
  data,
  comp 
)    list_add_sorted3((list_t *) (void *) list, (list_t) data, (void *) comp)
#define LIST_COUNT2 (   list)    list_count((list_t) list)
#define LIST_DESTROY (   list,
  func 
)    list_destroy2(list, (void *) func)
#define LIST_DESTROY2 (   list,
  func 
)    list_destroy3((list_t) list, (void *) func)
#define LIST_FREE_ITEM (   x,
  type 
)    void x(type data)
#define LIST_GET_NTH2 (   list,
  id 
)    list_get_nth3((list_t) list, id)
#define LIST_REMOVE (   list,
  data,
  func 
)    list_remove2(list, data, (void *) func)
#define LIST_REMOVE2 (   list,
  elem,
  func 
)    list_remove3((list_t *) (void *) list, (list_t) elem, (void *) func)
#define LIST_RESORT (   list,
  comp 
)    list_resort(list, (void *) comp)
#define LIST_RESORT2 (   list,
  comp 
)    list_resort3((list_t *) (void *) list, (void *) comp)
#define LIST_UNLINK2 (   list,
  elem 
)    list_unlink3((list_t *) (void *) list, (list_t) elem)

Dokumentacja definicji typów

typedef struct list* list_t
typedef struct string* string_t

Dokumentacja funkcji

int array_add ( char ***  array,
char *  string 
)
int array_add_check ( char ***  array,
char *  string,
int  casesensitive 
)
int array_contains ( char **  array,
const char *  string,
int  casesensitive 
)
int array_count ( char **  array)
void array_free ( char **  array)
void array_free_count ( char **  array,
int  count 
)
int array_item_contains ( char **  array,
const char *  string,
int  casesensitive 
)
char* array_join ( char **  array,
const char *  sep 
)
char* array_join_count ( char **  array,
const char *  sep,
int  count 
)
char** array_make ( const char *  string,
const char *  sep,
int  max,
int  trim,
int  quotes 
)
char* array_shift ( char ***  array)
const char* cssfind ( const char *  haystack,
const char *  needle,
const char  sep,
int  caseinsensitive 
)

cssfind()

Short for comma-separated string find, does check whether given string contains given element. It's works like array_make()+array_contains(), but it's hell simpler and faster.

Parametry:
haystack- comma-separated string to search.
needle- element to search for.
sep- separator.
caseinsensitive- take a wild guess.
Zwraca:
Pointer to found element on success, or NULL on failure.
char* escape ( const char *  src)
const char* itoa ( long int  i)
void* list_add ( list_t list,
void *  data 
)

list_add()

Add item data to list without sorting
Item will be added at end of list - as last item
Wrapper to: list_add_sorted(list, data, alloc_size, NULL)

Zobacz również:
list_remove()
list_add_beginning() - If you can have items of list in reverse sequence [third_added_item, second_added_item, first_added_item] and not sorted
list_add_sorted()
void* list_add3 ( list_t list,
list_t  new_ 
)
void* list_add_beginning ( list_t list,
void *  data 
)

list_add_beginning()

Add item data to the begining of the list
(Once again), item will be added at begining of the list - as first item

Zobacz również:
list_add()
list_remove()
void* list_add_beginning3 ( list_t list,
list_t  new_ 
)
void* list_add_sorted ( list_t list,
void *  data,
int(*)(void *, void *)  comparision 
)
void* list_add_sorted3 ( list_t list,
list_t  new_,
int(*)(void *, void *)  comparision 
)
void list_cleanup ( list_t list)

list_cleanup()

Remove from list_t all items with l->data set to NULL.
Use with list_remove_safe() after list is not in use.

int list_count ( list_t  list)

list_count()

Parametry:
list- list_t
Zwraca:
items count on list_t list.
int list_destroy ( list_t  list,
int  free_data 
)

list_destroy()

Destroy all items from list_t list

Nota:
It doesn't take pointer to list_t, and it don't cleanup memory with \0, so after list_destroy() you must remember that list is unaccessible. So if you have list as global variable, or if you keep pointer to it in some struct.. you must NULL pointer. so always do:
list_destroy(my_list, free_data); my_list = NULL;
Parametry:
list- list_t
free_data- if set we will call xfree() on each item data
Zobacz również:
list_remove() - to remove specified item.
Zwraca:
0
int list_destroy2 ( list_t  list,
void(*)(void *)  func 
)
int list_destroy3 ( list_t  list,
void(*)(void *)  func 
)
void* list_get_nth ( list_t  list,
int  id 
)

list_get_nth()

Get n'th item from list_t

Parametry:
list- list_t
id- n'th item [list items are numerated from 1]
Zwraca:
n'th item (list->data) if found, or NULL with errno set to ENOENT
void* list_get_nth3 ( list_t  list,
int  id 
)
int list_remove ( list_t list,
void *  data,
int  free_data 
)

list_remove()

Remove item data from list_t pointed by list

Parametry:
list- pointer to list_t
data- data to remove from list
free_data- if set and item was found it'll call xfree() on it.
Zobacz również:
list_destroy() - to remove whole list
Zwraca:
0 if item was founded, and was removed from list_t pointed by list
-1 and errno set to EFAULT, if list was NULL
-1 and errno set to ENOENT, if item was not found
int list_remove2 ( list_t list,
void *  data,
void(*)(void *)  func 
)
void* list_remove3 ( list_t list,
list_t  elem,
void(*)(list_t func 
)
void* list_remove3i ( list_t list,
list_t  elem,
void(*)(list_t data)  func 
)
int list_remove_safe ( list_t list,
void *  data,
int  free_data 
)

list_remove_safe()

Remove item data from list_t pointed by list.
Don't free whole list_t item struct. only set item_list_t->data to NULL

Nota:
XXX, add note here why we should do it.
Parametry:
list- pointer to list_t
data- data to remove from list
free_data-if set and item was found it'll call xfree() on it.
Zobacz również:
list_cleanup() - to remove NULL items from list.
void list_resort ( list_t list,
int(*)(void *, void *)  comparision 
)
void list_resort3 ( list_t list,
int(*)(void *, void *)  comparision 
)
void* list_unlink3 ( list_t list,
list_t  elem 
)
const char* private_item_get ( private_data_t **  data,
const char *  item_name 
)
int private_item_get_int ( private_data_t **  data,
const char *  item_name 
)
int private_item_get_int_safe ( private_data_t **  data,
const char *  item_name,
int *  result 
)
int private_item_get_safe ( private_data_t **  data,
const char *  item_name,
char **  result 
)
void private_item_set ( private_data_t **  data,
const char *  item_name,
const char *  value 
)
void private_item_set_int ( private_data_t **  data,
const char *  item_name,
int  value 
)
void private_items_destroy ( private_data_t **  data)
int string_append ( string_t  s,
const char *  str 
)

string_append()

Append to string_t s, NUL terminated string pointed by str
Wrapper to:string_append_n(s, str, -1)

Zobacz również:
string_append_n()
int string_append_c ( string_t  s,
char  c 
)

string_append_c()

Append to string_t s char c.

Parametry:
s- string_t
c- char to append
Zwraca:
0 on success
-1 and errno set to EFAULT if input params were wrong (s == NULL || format == NULL)
int string_append_format ( string_t  s,
const char *  format,
  ... 
)

string_append_format()

Append to string_t s, formatted output of format + params
Equivalent to:
char *tmp = saprintf(format, ...);
string_append(s, tmp);
xfree(tmp);

Nota:
For more details about string formating functions read man 3 vsnprintf
Zobacz również:
string_append() - If you want/can use non-formating function..
saprintf() - If you want to format output but to normal char *, not to string_t
Zwraca:
0 on success
-1 and errno set to EFAULT if input params were wrong (s == NULL || format == NULL)
int string_append_n ( string_t  s,
const char *  str,
int  count 
)

string_append_n()

Append to string_t s, first count chars, from str

Parametry:
s- string_t
str- buffer to append.
count- how many chars copy copy from str, or -1 to copy whole.
Do zrobienia:
We append here NUL terminated string, so maybe let's always do count = xstrnlen(str, count);?
Because now programmer can pass negative value, and it'll possible do SIGSEGV
Also we can allocate less memory for string, when for example str[count-3] was NUL char.
Zwraca:
0 on success
-1 and errno set to EFAULT if input params were wrong (s == NULL || str == NULL)
int string_append_raw ( string_t  s,
const char *  str,
int  count 
)

string_append_raw()

Append to string_t s, count bytes from memory pointed by str

Zobacz również:
string_append_n() - If you want to append NUL terminated (C-like) String
Do zrobienia:
XXX Protect from negative count (and less than -1) ?
void string_clear ( string_t  s)

string_clear()

Clear s->str (s->str[0] == '\0')
If memory allocated by string_t s was larger than 160, than decrease to 80

Parametry:
s- string_t
Zobacz również:
string_free() - To free memory allocated by string_t
char* string_free ( string_t  s,
int  free_string 
)

string_free()

Cleanup memory after string_t s, and perhaps (if free_string set) cleanup memory after char buffer.

Parametry:
s- string_t which we want to free.
free_string- do we want to free memory after char buffer?
Zobacz również:
string_clear() - if you just want to clear saved char buffer, and you don't want to free internal string_t struct.
Zwraca:
if free_string != 0 always NULL
else returns saved char buffer, which need be free()'d after use by xfree()
string_t string_init ( const char *  value)

string_init()

init string_t struct, allocating memory for string passed by value, and setting internal string_t data.

Parametry:
value- if NULL char buffer will be inited with "", otherwise with given value.
Zobacz również:
string_free() - to free memory used by string_t
Zwraca:
pointer to allocated string_t struct.
void string_insert ( string_t  s,
int  index,
const char *  str 
)

string_insert()

Insert given text (str) to given string_t (s) at given pos (index)
Wrapper to: string_insert_t(s, index, str, -1)

Parametry:
s- string_t
index- pos
str- text
Zobacz również:
string_insert_n()
void string_insert_n ( string_t  s,
int  index,
const char *  str,
int  count 
)
void string_remove ( string_t  s,
int  count 
)

string_remove()

Remove first count chars from string.

char* unescape ( const char *  src)
 All Struktury Danych Pliki Funkcje Zmienne Definicje typów Wyliczenia Wartości wyliczeń Definicje