mirror of
https://github.com/nextcloud/desktop.git
synced 2024-10-25 05:45:42 +03:00
Merge branch 'master' of git://git.csync.org/projects/csync/csync
This commit is contained in:
commit
73548e8a16
2 changed files with 33 additions and 23 deletions
|
@ -33,8 +33,8 @@
|
||||||
* Adds a new element on to the end of the list.
|
* Adds a new element on to the end of the list.
|
||||||
*/
|
*/
|
||||||
c_list_t *c_list_append(c_list_t *list, void *data) {
|
c_list_t *c_list_append(c_list_t *list, void *data) {
|
||||||
c_list_t *new = NULL;
|
c_list_t *new;
|
||||||
c_list_t *last = NULL;
|
c_list_t *last;
|
||||||
|
|
||||||
new = c_list_alloc();
|
new = c_list_alloc();
|
||||||
if (new == NULL) {
|
if (new == NULL) {
|
||||||
|
@ -58,8 +58,8 @@ c_list_t *c_list_append(c_list_t *list, void *data) {
|
||||||
* Adds a new element on at the beginning of the list.
|
* Adds a new element on at the beginning of the list.
|
||||||
*/
|
*/
|
||||||
c_list_t *c_list_prepend(c_list_t *list, void *data) {
|
c_list_t *c_list_prepend(c_list_t *list, void *data) {
|
||||||
c_list_t *new = NULL;
|
c_list_t *new;
|
||||||
c_list_t *first = NULL;
|
c_list_t *first;
|
||||||
|
|
||||||
new = c_list_alloc();
|
new = c_list_alloc();
|
||||||
if (new == NULL) {
|
if (new == NULL) {
|
||||||
|
@ -81,8 +81,8 @@ c_list_t *c_list_prepend(c_list_t *list, void *data) {
|
||||||
* Inserts a new element into the list at the given position.
|
* Inserts a new element into the list at the given position.
|
||||||
*/
|
*/
|
||||||
c_list_t *c_list_insert(c_list_t *list, void *data, long position) {
|
c_list_t *c_list_insert(c_list_t *list, void *data, long position) {
|
||||||
c_list_t *new = NULL;
|
c_list_t *new;
|
||||||
c_list_t *temp = NULL;
|
c_list_t *temp;
|
||||||
|
|
||||||
/* Handle wrong values for position */
|
/* Handle wrong values for position */
|
||||||
if (position < 0) {
|
if (position < 0) {
|
||||||
|
@ -93,7 +93,7 @@ c_list_t *c_list_insert(c_list_t *list, void *data, long position) {
|
||||||
|
|
||||||
temp = c_list_position(list, position);
|
temp = c_list_position(list, position);
|
||||||
|
|
||||||
if (!temp) {
|
if (temp == NULL) {
|
||||||
return c_list_append(list, data);
|
return c_list_append(list, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,9 +124,10 @@ c_list_t *c_list_insert(c_list_t *list, void *data, long position) {
|
||||||
* Inserts a new element into the list, using the given comparison function to
|
* Inserts a new element into the list, using the given comparison function to
|
||||||
* determine its position.
|
* determine its position.
|
||||||
*/
|
*/
|
||||||
c_list_t *c_list_insert_sorted(c_list_t *list, void *data, c_list_compare_fn func) {
|
c_list_t *c_list_insert_sorted(c_list_t *list, void *data,
|
||||||
c_list_t *new = NULL;
|
c_list_compare_fn func) {
|
||||||
c_list_t *temp = NULL;
|
c_list_t *new;
|
||||||
|
c_list_t *temp;
|
||||||
int cmp;
|
int cmp;
|
||||||
|
|
||||||
new = c_list_alloc();
|
new = c_list_alloc();
|
||||||
|
@ -150,7 +151,7 @@ c_list_t *c_list_insert_sorted(c_list_t *list, void *data, c_list_compare_fn fun
|
||||||
}
|
}
|
||||||
|
|
||||||
/* last element */
|
/* last element */
|
||||||
if ((!temp->next) && (cmp > 0)) {
|
if ((temp->next == NULL) && (cmp > 0)) {
|
||||||
temp->next = new;
|
temp->next = new;
|
||||||
new->prev = temp;
|
new->prev = temp;
|
||||||
return list;
|
return list;
|
||||||
|
@ -197,7 +198,7 @@ c_list_t *c_list_alloc(void) {
|
||||||
* only the first is removed.
|
* only the first is removed.
|
||||||
*/
|
*/
|
||||||
c_list_t *c_list_remove(c_list_t *list, void *data) {
|
c_list_t *c_list_remove(c_list_t *list, void *data) {
|
||||||
c_list_t *temp = NULL;
|
c_list_t *temp;
|
||||||
|
|
||||||
if (list == NULL || data == NULL) {
|
if (list == NULL || data == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -355,7 +356,8 @@ c_list_t *c_list_find(c_list_t *list, void *data) {
|
||||||
* Finds an element, using a supplied function to find the desired
|
* Finds an element, using a supplied function to find the desired
|
||||||
* element.
|
* element.
|
||||||
*/
|
*/
|
||||||
c_list_t *c_list_find_custom(c_list_t *list, void *data, c_list_compare_fn func) {
|
c_list_t *c_list_find_custom(c_list_t *list, void *data,
|
||||||
|
c_list_compare_fn func) {
|
||||||
int cmp;
|
int cmp;
|
||||||
|
|
||||||
if (list != NULL && func != NULL) {
|
if (list != NULL && func != NULL) {
|
||||||
|
@ -374,7 +376,8 @@ c_list_t *c_list_find_custom(c_list_t *list, void *data, c_list_compare_fn func)
|
||||||
/*
|
/*
|
||||||
* Internal used function to merge 2 lists using a compare function
|
* Internal used function to merge 2 lists using a compare function
|
||||||
*/
|
*/
|
||||||
static c_list_t *_c_list_merge(c_list_t *list1, c_list_t *list2, c_list_compare_fn func) {
|
static c_list_t *_c_list_merge(c_list_t *list1, c_list_t *list2,
|
||||||
|
c_list_compare_fn func) {
|
||||||
int cmp;
|
int cmp;
|
||||||
|
|
||||||
/* lists are emty */
|
/* lists are emty */
|
||||||
|
@ -413,7 +416,7 @@ static c_list_t *_c_list_split(c_list_t *list) {
|
||||||
/* list has only 1 element */
|
/* list has only 1 element */
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
/* split */
|
/* split */
|
||||||
second = list->next;
|
second = list->next;
|
||||||
list->next = second->next;
|
list->next = second->next;
|
||||||
/* is last element */
|
/* is last element */
|
||||||
|
@ -427,15 +430,19 @@ static c_list_t *_c_list_split(c_list_t *list) {
|
||||||
if (second->next) {
|
if (second->next) {
|
||||||
second->next->prev = second;
|
second->next->prev = second;
|
||||||
}
|
}
|
||||||
|
|
||||||
return second;
|
return second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* never reached */
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sorts the elements of a c_list.
|
* Sorts the elements of a c_list. This is a merge sort.
|
||||||
*/
|
*/
|
||||||
c_list_t *c_list_sort(c_list_t *list, c_list_compare_fn func) {
|
c_list_t *c_list_sort(c_list_t *list, c_list_compare_fn func) {
|
||||||
c_list_t *second = NULL;
|
c_list_t *second;
|
||||||
|
|
||||||
/* list is empty */
|
/* list is empty */
|
||||||
if (list == NULL) {
|
if (list == NULL) {
|
||||||
|
@ -448,6 +455,7 @@ c_list_t *c_list_sort(c_list_t *list, c_list_compare_fn func) {
|
||||||
second = _c_list_split(list);
|
second = _c_list_split(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
return _c_list_merge(c_list_sort(list, func), c_list_sort(second, func), func);
|
return _c_list_merge(c_list_sort(list, func), c_list_sort(second, func),
|
||||||
|
func);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -138,7 +138,8 @@ c_list_t *c_list_insert(c_list_t *list, void *data, long position);
|
||||||
* @return New start of the list, which may have changed, so make
|
* @return New start of the list, which may have changed, so make
|
||||||
* sure you store the new value.
|
* sure you store the new value.
|
||||||
*/
|
*/
|
||||||
c_list_t *c_list_insert_sorted(c_list_t *list, void *data, c_list_compare_fn func);
|
c_list_t *c_list_insert_sorted(c_list_t *list, void *data,
|
||||||
|
c_list_compare_fn func);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allocates space for one c_list_t element.
|
* Allocates space for one c_list_t element.
|
||||||
|
@ -249,7 +250,8 @@ c_list_t *c_list_find(c_list_t *list, void *data);
|
||||||
*
|
*
|
||||||
* @return The found element or NULL if it is not found.
|
* @return The found element or NULL if it is not found.
|
||||||
*/
|
*/
|
||||||
c_list_t *c_list_find_custom(c_list_t *list, void *data, c_list_compare_fn func);
|
c_list_t *c_list_find_custom(c_list_t *list, void *data,
|
||||||
|
c_list_compare_fn func);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sorts the elements of a c_list.
|
* Sorts the elements of a c_list.
|
||||||
|
@ -261,9 +263,9 @@ c_list_t *c_list_find_custom(c_list_t *list, void *data, c_list_compare_fn func)
|
||||||
*
|
*
|
||||||
* @param func The comparison function used to sort the c_list. This
|
* @param func The comparison function used to sort the c_list. This
|
||||||
* function is passed 2 elements of the GList and should
|
* function is passed 2 elements of the GList and should
|
||||||
* return 0 if they are equal, a negative value if the first
|
* return 0 if they are equal, a negative value if the
|
||||||
* element comes before the second, or a positive value if the
|
* first element comes before the second, or a positive
|
||||||
* first element comes after the second.
|
* value if the first element comes after the second.
|
||||||
*
|
*
|
||||||
* @return New start of the list, which may have changed, so make
|
* @return New start of the list, which may have changed, so make
|
||||||
* sure you store the new value.
|
* sure you store the new value.
|
||||||
|
|
Loading…
Reference in a new issue