ftp.nice.ch/pub/next/unix/developer/docgen.0.3.2.s.tar.gz#/docgen-0.3.2/dlist/dlist.h

This is dlist.h in view mode; [Download] [Up]

/* dlist v1.0.0	Dynamic list library
 * Copyright (c) 1994 Bill Bereza
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *
 * To reach the author
 *
 * email:
 *	berezaw@river.it.gvsu.edu	ac368@leo.nmc.edu
 *
 *	$Log:	dlist.h,v $
 * Revision 1.6  94/12/22  02:47:55  berezaw
 * added dlistmemusage() macro
 * 
 * Revision 1.5  94/12/20  22:53:06  berezaw
 * did some fiddling with qsort
 * 
 * Revision 1.4  94/12/19  22:19:08  berezaw
 * *** empty log message ***
 * 
 * Revision 1.3  94/12/19  21:17:30  berezaw
 * finished quick sort function
 * 
 * Revision 1.2  94/12/19  13:16:15  berezaw
 * made daddel functions macros for a more general function
 * 
 * Revision 1.1  94/12/17  21:54:24  berezaw
 * Initial revision
 * 
 *
 *	$Header: /Users/berezaw/src/dlist/RCS/dlist.h,v 1.6 94/12/22 02:47:55 berezaw Exp $
 */

#ifndef _DLIST_H
#define _DLIST_H

#include <stdlib.h>
#include <stddef.h>
#include <string.h>

struct __dlstflags {
	unsigned int is_linked : 1;
};
#define __DFLAGS	struct __dlstflags

struct _del {					/* normal element structure */
	void 	*_element;
	struct	_del	*_prev;
	struct 	_del 	*_next;
};
#define _DEL 	struct _del

struct _delv {					/* variable element structure */
	void 	*_element;
	struct	_delv	*_prev;
	struct 	_delv 	*_next;
	size_t	_elvsize;
};
#define _DELV	struct _delv

struct 	_dlist {
	void	*_first;
	void	*_last;
	size_t	_bytes;
	size_t	_elems;
	size_t	_elsize;
	__DFLAGS	_flags;
};

#define DLIST	struct _dlist

extern DLIST	*_initdlist(size_t obs, int lnk);
#define initdlist(s)	_initdlist((s),0)
#define initdlink(s)	_initdlist((s),1)
/* initdlist will allocate space for the dlist structure
 * and set all the values in the structure to zero or null
 *
 * It will set the element size to obs. If obs is zero, then
 * the element size will be variable
 *
 * initdlink will create a list where the element space
 * will only point to some previously allocated space
 *
 * you will have to free it.
 *
 * returns pointer to DLIST if successful, else returns NULL
 */

#define DLST_ISLINKED(s)	((s)->_flags.is_linked)
#define DLST_SAVE(s)	(((s)->_flags.is_linked)=1)
#define DLST_FREE(s)	(((s)->_flags.is_linked)=0)

extern void 	freeels(DLIST *oldlist);
/* freeels frees all the elements in the dlist
 * and resets the length to zero
 *
 * the argument must be a previously initialized dlist
 *
 * no return value
 */

extern void 	freedlist(DLIST *oldlist);
/* freedlist will free all space used by the dlist struct
 * including the list of elements
 *
 * the argument should be a dlist struct pointer that has already been allocated
 *
 * freedlist has no return value
 */

extern void *__daddel(DLIST *dstr, void *addel, size_t els);

#define daddel(l,a)	__daddel((l),(a),0)
/* daddel will add one element to the dlist
 *
 * dlist must already be initialized with initdlist first
 *
 * daddel returns NULL if it couldn't add an element
 * and returns a pointer to added if successful
 */

#define daddelv(l,a,s)	__daddel((l),(a),(s))
/* daddelv will add one character to the dlist
 *
 * dlist must already be initialized with initdlist first
 *
 * daddelv returns NULL if it couldn't add an element
 * and returns the pointer to the element added if successful
 */

#define dlistbytes(l)	((l)->_bytes)
/* dlistbytes returns the number of bytes in the DLISt
 *
 * the dlist must already be initialized
 */

/* extern size_t 	dlistels(DLIST *oldlist); */
#define dlistels(l)	((l)->_elems)
#define dlistsize(l)	dlistels(l)
/* dlistels returns the number of elements in the DLISt
 *
 * the dlist must already be initialized
 */

/* extern size_t 	delsize(DLIST *oldlist); */
#define delsize(l)	((l)->_elsize)
/* delsize returns the size of elements in the DLISt
 *
 * the dlist must already be initialized
 */

#define dlistmemusage(q)	(sizeof(DLIST)+(DLST_ISLINKED(q) ? 0 : dlistbytes(q))+(dlistsize(q)*(delsize(q) ? sizeof(_DEL) : sizeof(_DELV))))

extern void  	*arrdlist(DLIST *oldlist);
/* arrdlist will allocate space for an array and
 * copy all elements from DLIST into the array
 *
 * This function can only be used if the list uses
 * non-variable elements
 *
 * DLIST must be previously initialized
 *
 * returns a pointer to the array
 */

extern DLIST *__dlistcat(DLIST *ostr, DLIST *addstr);

#define dlistcat(t,f)	__dlistcat((t),(f))
/* dlistcat appends the elements from the second dlist onto the end
 * of the first dlist
 *
 * both arguments must be previously initialized dlist
 *
 * returns NULL on error, else returns pointer to the first list
 */

#define dlistcpy(f)	__dlistcat((initdlist(delsize(f))), (f))
/* dlistcpy copies the elements from the second dlist and creates another dlist
 * pointed to by the first dstring pointer
 *
 * the second dlist must be previously initialized
 *
 * returns NULL on error, else returns a pointer to the new dlist
 */

#define dlistlnk(f)	__dlistcat((initdlink(delsize(f))), (f))
/* dlistcpy copies the elements from the second dlist and creates another dlist
 * pointed to by the first dstring pointer
 *
 * Both of the dlists will be pointing to the same data
 * This allows you to have a sorted and unsorted version
 * of the same data.
 *
 * the second dlist must be previously initialized
 *
 * returns NULL on error, else returns a pointer to the new dlist
 */

#define __DELCMPARGS	void *, void *

extern DLIST *dlstinsertsort(DLIST *tosort, int (*elcmp)(__DELCMPARGS));
/* perform Insertion Sort on the list
 *
 * returns a pointer to the new sorted list
 */

extern DLIST *dlstsort(DLIST *tosort, int (*elcmp)(__DELCMPARGS));
/* perform best possible sort on the list
 *
 * this will perform an optimised quick sort on the list
 * (when I finish the qsort function)
 *
 * returns a pointer to the sorted list
 */

#endif /* !_DLIST_H */

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.