Beispiel #1
0
/*
 *	Delete a child from the parent list, but do not free child.
 */
void pdb_del_child_list_node_cb(struct pdb_node_t* pptr,
	struct pdb_node_t* nptr) {

	struct linkList* lptr = pptr->data;
	struct linkNode* lnptr = lptr->root;
	
	while (lnptr) {
		if (lnptr->data == nptr) {
			list_delink_node(lptr, lnptr);
			return;
		}
	}
}
Beispiel #2
0
/*
 *	DeLink Node and Free Memory
 *	Previously Allocated for
 *	the Data it Contains
 *
 *	If free_data is set
 *	to 0, the data will not
 *	be released.
 *
 *	If free_callback is not
 *	NULL and free_data is 1,
 *	use the given callback
 *	to free the data.
 */
int list_free_node(struct linkList* lptr, struct linkNode* nptr,
	int free_data, list_func_ptr free_callback) {
	
 	if (!list_delink_node(lptr, nptr))
		return 0;
	
	if (free_data) {
		if (free_callback)
			/*
			 *	Use the given callback
			 *	to free the data.
			 */
			free_callback(nptr->data);
		else
			free(nptr->data);
	}

	free(nptr);
	return 1;
}
Beispiel #3
0
/*
 *	Write a link list node to disk.
 */
int pdb_write_list_node_cb(struct pdb* dbptr, FILE* fptr,
	struct pdb_node_t* nptr, int tabs) {

	struct linkList* lptr = nptr->data;
	struct linkNode* lnptr = lptr->root;
	
	/*
	 *	Set PDB_WRITE_NODE_FIRST_ID as the first in the list
	 *	if PDB_WRITE_NODE_FIRST is set.
	 *	Only if root node.
	 */
	if (!tabs) {
		if (pdb_is_set(dbptr, PDB_WRITE_NODE_FIRST)) {
			while (lnptr) {
				nptr = lnptr->data;
				if (!strcmp(nptr->id, PDB_WRITE_NODE_FIRST_ID)) {
					list_delink_node(lptr, lnptr);
					list_add_node_front(lptr, nptr);
					break;
				}
				lnptr = lnptr->next;
			}
		}
	}
	
	/*
	 *	Write all children to disk.
	 */
	lnptr = lptr->root;
	while (lnptr) {
		nptr = lnptr->data;
		if (!pdb_standard_write_node(dbptr, fptr, nptr, tabs))
			return 0;
		lnptr = lnptr->next;
	}
	
	return 1;
}