JST: JSON tools  1.0.0
JSON tools dynamic library for reading, manipulating and writing JSON tree
JST_list.c
Go to the documentation of this file.
1 #include "JST_list.h"
2 
3 #include <stdlib.h>
4 
5 const JST_List JST_List_Zero = { .item = NULL, .next = NULL };
6 
7 JST_Error JST_List_push_back( JST_List ** first, JST_List ** current, void * data ) {
8  if(( first == NULL )||( current == NULL )) {
10  }
11  if( *first == NULL ) {
12  *first = *current = calloc( 1, sizeof( JST_List ));
13  }
14  else {
15  if( *current == NULL ) {
16  return JST_ERR_NULL_ARGUMENT;
17  }
18  (*current)->next = calloc( 1, sizeof( JST_List ));
19  *current = (*current)->next;
20  }
21  (*current)->item = data;
22  return JST_ERR_NONE;
23 }
24 
25 JST_Error JST_List_move_to( JST_List * from, void * dest, LST_assign_t assign ) {
26  if(( from == NULL )||( dest == NULL )||( assign == NULL )) {
27  return JST_ERR_NULL_ARGUMENT;
28  }
29  JST_List * iter = from;
30  for( unsigned i = 0; iter; ++i ) {
31  assign( dest, i, iter->item );
32  JST_List * next = iter->next;
33  free( iter );
34  iter = next;
35  }
36  return JST_ERR_NONE;
37 }
struct JST_Node_ * next
Definition: JST_list.h:6
void * item
Definition: JST_list.h:5
void(* LST_assign_t)(void *dest, unsigned index, void *src)
Definition: JST_list.h:11
JST_Error JST_List_push_back(JST_List **first, JST_List **current, void *data)
Definition: JST_list.c:7
JST_Error
When things goes wrong, an error information is given.
Definition: jstools.h:108
JST_Error JST_List_move_to(JST_List *from, void *dest, LST_assign_t assign)
For each item in list, call assign to transfert ownership of items and free the list, node by node.
Definition: JST_list.c:25
const JST_List JST_List_Zero
Definition: JST_list.c:5
Function misused.
Definition: jstools.h:110