From fc1f9cb5ffcbc0103beb0c03d3bc0f4543f4148b Mon Sep 17 00:00:00 2001 From: Karl Ramm Date: Sat, 10 Oct 2009 15:08:21 +0000 Subject: With xzwrite gone, we don't need libdyn. --- Makefile.in | 2 +- configure.in | 2 +- h/dyn.h | 56 ------------ libdyn/Makefile.in | 52 ----------- libdyn/README | 32 ------- libdyn/dyn.3 | 233 -------------------------------------------------- libdyn/dynP.h | 49 ----------- libdyn/dyn_append.c | 44 ---------- libdyn/dyn_create.c | 49 ----------- libdyn/dyn_debug.c | 25 ------ libdyn/dyn_delete.c | 77 ----------------- libdyn/dyn_header.c | 11 --- libdyn/dyn_insert.c | 61 ------------- libdyn/dyn_paranoid.c | 25 ------ libdyn/dyn_put.c | 83 ------------------ libdyn/dyn_realloc.c | 50 ----------- libdyn/dyn_size.c | 24 ------ libdyn/dyntest.c | 132 ---------------------------- 18 files changed, 2 insertions(+), 1005 deletions(-) delete mode 100644 h/dyn.h delete mode 100644 libdyn/Makefile.in delete mode 100644 libdyn/README delete mode 100644 libdyn/dyn.3 delete mode 100644 libdyn/dynP.h delete mode 100644 libdyn/dyn_append.c delete mode 100644 libdyn/dyn_create.c delete mode 100644 libdyn/dyn_debug.c delete mode 100644 libdyn/dyn_delete.c delete mode 100644 libdyn/dyn_header.c delete mode 100644 libdyn/dyn_insert.c delete mode 100644 libdyn/dyn_paranoid.c delete mode 100644 libdyn/dyn_put.c delete mode 100644 libdyn/dyn_realloc.c delete mode 100644 libdyn/dyn_size.c delete mode 100644 libdyn/dyntest.c diff --git a/Makefile.in b/Makefile.in index 30d375c..c7b438c 100644 --- a/Makefile.in +++ b/Makefile.in @@ -17,7 +17,7 @@ top_srcdir=@top_srcdir@ ENSUREDIR=${srcdir}/ensure-dir.sh INSTALL=@INSTALL@ -SUBDIRS=lib libdyn clients server zhm zwgc +SUBDIRS=lib clients server zhm zwgc build: $(MAKE) all diff --git a/configure.in b/configure.in index 2832b45..36cdabe 100644 --- a/configure.in +++ b/configure.in @@ -283,5 +283,5 @@ AC_OUTPUT(Makefile clients/Makefile clients/zaway/Makefile clients/zctl/Makefile clients/zleave/Makefile clients/zlocate/Makefile clients/znol/Makefile clients/zshutdown_notify/Makefile clients/zstat/Makefile - clients/zwrite/Makefile lib/Makefile libdyn/Makefile + clients/zwrite/Makefile lib/Makefile server/Makefile zhm/Makefile zwgc/Makefile) diff --git a/h/dyn.h b/h/dyn.h deleted file mode 100644 index 6823b75..0000000 --- a/h/dyn.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is part of libdyn.a, the C Dynamic Object library. It - * contains the public header file. - * - * There are no restrictions on this code; however, if you make any - * changes, I request that you document them so that I do not get - * credit or blame for your modifications. - * - * Written by Barr3y Jaspan, Student Information Processing Board (SIPB) - * and MIT-Project Athena, 1989. - */ - - -/* - * dyn.h -- header file to be included by programs linking against - * libdyn.a. - */ - -#ifndef _Dyn_h -#define _Dyn_h - -/* Reliance on for __P() below makes this unsuitable for use - * outside of the Zephyr source tree. */ -#include - -typedef char *DynPtr; -typedef struct _DynObject *DynObject; - -/* Function macros */ -#define DynHigh(obj) (DynSize(obj) - 1) -#define DynLow(obj) (0) - -#ifdef SUNOS -#define memmove(a, b, c) bcopy(b, a, c) -#endif - -/* Return status codes */ -#define DYN_OK -1000 -#define DYN_NOMEM -1001 -#define DYN_BADINDEX -1002 -#define DYN_BADVALUE -1003 - -/* Function declarations */ -int DynAppend __P((DynObject obj, DynPtr els, int num)); -int DynAdd __P((DynObject obj, DynPtr el)); -DynObject DynCreate __P((int el_size, int inc)); -int DynDebug __P((DynObject obj, int state)); -int DynDelete __P((DynObject obj, int idx)); -int DynDestroy __P((DynObject obj)); -DynPtr DynGet __P((DynObject obj, int num)); -int DynInsert __P((DynObject obj, int idx, DynPtr els, int num)); -int DynParanoid __P((DynObject obj, int state)); -int DynSize __P((DynObject obj)); - -#endif /* _Dyn_h */ -/* DO NOT ADD ANYTHING AFTER THIS #endif */ diff --git a/libdyn/Makefile.in b/libdyn/Makefile.in deleted file mode 100644 index ecd0c41..0000000 --- a/libdyn/Makefile.in +++ /dev/null @@ -1,52 +0,0 @@ -SHELL = /bin/sh - -prefix=@prefix@ -exec_prefix=@exec_prefix@ -datadir=@datadir@ -sysconfdir=@sysconfdir@ -sbindir=@sbindir@ -lsbindir=@lsbindir@ -datarootdir=@datarootdir@ - -includedir=${prefix}/include -mandir=@mandir@ -libdir=${exec_prefix}/lib - -srcdir=@srcdir@ -top_srcdir=@top_srcdir@ -BUILDTOP=.. -VPATH=@srcdir@ -CC=@CC@ -RANLIB=@RANLIB@ - -CPPFLAGS=@CPPFLAGS@ -CFLAGS=@CFLAGS@ -ALL_CFLAGS=${CFLAGS} -I${top_srcdir}/h -I${BUILDTOP}/h ${CPPFLAGS} - -OBJS = dyn_append.o dyn_create.o dyn_debug.o dyn_delete.o dyn_insert.o \ - dyn_paranoid.o dyn_put.o dyn_realloc.o dyn_size.o - -all: libdyn.a dyntest - -libdyn.a: ${OBJS} - ar cru $@ ${OBJS} - ${RANLIB} $@ - -dyntest: libdyn.a dyntest.o - ${CC} ${LDFLAGS} -o $@ dyntest.o libdyn.a - -.c.o: - ${CC} -c ${ALL_CFLAGS} $< - -check: - -install: - -clean: - rm -f ${OBJS} libdyn.a dyntest.o dyntest - -${OBJS} dyntest.o: dynP.h ${top_srcdir}/h/dyn.h ${top_srcdir}/h/sysdep.h -${OBJS} dyntest.o: ${BUILDTOP}/h/config.h - -.PHONY: all check install clean - diff --git a/libdyn/README b/libdyn/README deleted file mode 100644 index 0c08ac5..0000000 --- a/libdyn/README +++ /dev/null @@ -1,32 +0,0 @@ -libdyn.a -- Release 1.0 - -A C Dynamic Object is an array that takes care of resizing itself as -elements are added and deleted from it. It can be of any type for -which sizeof is defined and for which an address of a variable of that -type can be passed to a function. - -To build libdyn.a, simply type "make depend all" (if you don't have -the program makedepend, of course, leave out the "depend" part). If -your system's bcopy() cannot handle overlapping regions, you'll need -to write one that can. (Left as an excercise for the reader..) - -The library should compile and work without modification on a vast -number of systems. It only uses 5 external functions: malloc, -realloc, free, bcopy, and fprintf (to stderr). Of these, only bcopy -should need to be changed for other systems (such as MS-DOS) and it -could probably be done with a -D flag to the compiler. - -The test/demo program is built by "make all". This program produces -the library's debugging output (to stderr) as well as some of its own -output (to stdout). - -The library has been tested (with test.c) on a VAX VSII, VAXstation -3100, DECstation 3100, and IBM RT all running BSD4.3 (except for the -DECstation, which was running Ultrix V2.1). - -An earlier version of this library was posted to alt.sources. This -version contains one new function (DynInsert) and slightly cleaner -code, but no bugfixes (no bugs were found). - -Author: Barr3y Jaspan, Student Information Processing Board (SIPB) and -MIT-Project Athena, bjaspan@athena.mit.edu, 1990 diff --git a/libdyn/dyn.3 b/libdyn/dyn.3 deleted file mode 100644 index 0376b2f..0000000 --- a/libdyn/dyn.3 +++ /dev/null @@ -1,233 +0,0 @@ -.TH DYN 3M "15 March 1990" - -.SH NAME -dyn \- the C Dynamic Object library - -.SH DESCRIPTION - -A C Dynamic Object is an array that takes care of resizing -itself as you add and delete elements from it. It can be of any type -for which sizeof is defined and for which an address of a variable of -that type can be passed to a function. The library containing the -functions described below is called -.IR libdyn.a , -and the necessary declarations to use them are in -.RI < dyn.h >. -.PP -A DynObject is actually a structure that contains an array and a -couple of integers to maintain necessary state information. When a -Dyn function is said to operate on "the object" or "the array", it is -operating on the array stored in the structure while at the same time -updating internal state information. - -.SH LIST OF FUNCTIONS -.nf -DynObject DynCreate(size, increment) - int size, increment; -.fi -.PP -.IR Requires : -.I size -and -.I increment -are greater than zero. -.PP -.IR Effects : -Creates a new DynObject that will store elements of size -.I size -and will allocate memory in blocks large enough to hold exactly -.I increment -elements. For example, if you are storing 8-byte double -precision numbers and -.I increment -is 5, each 5th element you add to the object will cause it to request -40 more bytes (8 * 5) from the operating system. If -.I increment -is zero, a default value is used (currently 100). This is the only -time the programmer deals with a dynamic object's memory allocation. -.PP -.IR Returns : -.B DynCreate -returns the new DynObject, or NULL if there is insufficient memory. -.PP -.nf -int DynDestroy(obj) - DynObject obj; -.fi -.PP -.IR Modifies : -obj -.PP -.IR Effects : -Frees all memory associated with -.IR obj . -The results of calling any Dyn function on a destroyed object are -undefined (except for DynCreate, which resets the object). -.PP -.IR Returns : -.B DynDestroy -returns DYN_OK. -.PP -.nf -int DynAdd(obj, el) - DynObject obj; - DynPtr el; -.fi -.PP -.IR Modifies : -obj -.PP -.IR Effects : -Adds the element pointed to by -.I el -to the object -.IR obj , -resizing the object if necessary. -The new element becomes the last element in obj's array. -.PP -.IR Returns : -.B DynAdd -returns DYN_OK on success or DYN_NOMEM if there is insufficient -memory. -.PP -.nf -int DynInsert(obj, index, els, num) - DynObject obj; - DynPtr els; - int index, num; -.fi -.PP -.IR Modifies : -obj -.PP -.IR Effects : -Inserts the array of -.I num -elements, pointed to by -.IR els, -into the object -.I obj -starting at the array location -.IR index , -resizing the object if necessary. Order is preserved; if you have the -array "1 2 3 4 5" and insert "10 11 12" at the third position, you -will have the array "1 2 10 11 12 3 4 5". -.PP -.IR Returns : -.B DynInsert -returns DYN_BADINDEX if -.I index -is not between 0 and -.BR DynSize ( obj ) ; -DYN_BADVALUE if -.I num -is less than 1; DYN_NOMEM if there is insufficient memory. -.PP -.nf -int DynGet(obj, index) - DynObject obj; - int index; -.fi -.PP -.IR Effects : -Returns the address of the element -.I index -in the array of -.IR obj . -This pointer can be treated as a normal array of the type specified to -.BR DynCreate . -The order of elements in this array is the order in which they were -added to the object. The returned pointer is guaranteed to be valid -only until obj is modified. -.PP -.IR Returns : -.B DynGet -returns NULL if -.I index -is larger than the number of elements in the array of less than zero. -.PP -.nf -int DynDelete(obj, index) - DynObject obj; - int index; -.fi -.PP -.IR Modifies : -obj -.PP -.IR Effects : -The element -.I index -is deleted from the object -.IR obj . -Note that the element is actually removed permanently from the array. -If you have the array "1 2 3 4 5" and delete the third element, you -will have the array "1 2 4 5". The order of elements in not affected. -.PP -.IR Returns : -.B DynDelete -will return DYN_OK on success or DYN_BADINDEX if the element -.I index -does not exist in the array or is less than zero. -.PP -.nf -int DynSize(obj) - DynObject obj; -.fi -.PP -.IR Effects : -Returns the number of elements in the object -.IR obj . -.PP -.nf -int DynHigh(obj) - DynObject obj; -.fi -.PP -.IR Effects : -Returns the index of the highest element in the object -.IR obj . -In this version, -.B DynHigh -is macro that expands to -.B DynSize -- 1. -.PP -.nf -int DynLow(obj) - DynObject obj; -.fi -.PP -.IR Effects : -Returns the index of the lowest element in the object -.IR obj . -In this version, -.B DynLow -is macro that expands to 0. -.PP -.nf -int DynDebug(obj, state) - DynObject obj; - int state; -.fi -.PP -.IR Modifies : -obj -.PP -.IR Effects : -Sets the debugging state of -.I obj -to -.I state -and prints a message on stderr saying what state debugging was set to. -Any non-zero value for -.I state -turns debugging ``on''. When debugging is on, all Dyn functions will -produce (hopefully useful) output to stderr describing what is going on. -.PP -.IR Returns : -.B DynDebug -returns DYN_OK. -.SH AUTHOR -Barr3y Jaspan, Student Information Processing Board (SIPB) and -MIT-Project Athena, bjaspan@athena.mit.edu diff --git a/libdyn/dynP.h b/libdyn/dynP.h deleted file mode 100644 index 26ef10f..0000000 --- a/libdyn/dynP.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * This file is part of libdyn.a, the C Dynamic Object library. It - * contains the private header file. - * - * There are no restrictions on this code; however, if you make any - * changes, I request that you document them so that I do not get - * credit or blame for your modifications. - * - * Written by Barr3y Jaspan, Student Information Processing Board (SIPB) - * and MIT-Project Athena, 1989. - */ - - -/* - * dynP.h -- private header file included by source files for libdyn.a. - */ - -#ifndef _DynP_h -#define _DynP_h - -#include -#include - -/* - * Rep invariant: - * 1) el_size is the number of bytes per element in the object - * 2) num_el is the number of elements currently in the object. It is - * one higher than the highest index at which an element lives. - * 3) size is the number of elements the object can hold without - * resizing. num_el <= index. - * 4) inc is a multiple of the number of elements the object grows by - * each time it is reallocated. - */ - -typedef struct _DynObject { - DynPtr array; - int el_size, num_el, size, inc; - char debug, paranoid; -} DynObjectRec; - -/* Internal functions */ -int _DynRealloc __P((DynObject obj, int num_incs)); - -#define _DynResize(obj, req) \ - ((obj)->size > (req) ? DYN_OK : \ - (_DynRealloc((obj), (((req) - (obj)->size) / (obj)->inc) + 1))) - -#endif /* _DynP_h */ -/* DON'T ADD STUFF AFTER THIS #endif */ diff --git a/libdyn/dyn_append.c b/libdyn/dyn_append.c deleted file mode 100644 index 541aa0c..0000000 --- a/libdyn/dyn_append.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - * This file is part of libdyn.a, the C Dynamic Object library. It - * contains the source code for the function DynAppend(). - * - * There are no restrictions on this code; however, if you make any - * changes, I request that you document them so that I do not get - * credit or blame for your modifications. - * - * Written by Barr3y Jaspan, Student Information Processing Board (SIPB) - * and MIT-Project Athena, 1989. - */ - -#include - -#include "dynP.h" - -int -DynAppend(DynObject obj, - DynPtr els, - int num) -{ - if (obj->debug) - fprintf(stderr, "dyn: append: Writing %d bytes from %p to %p + %d\n", - obj->el_size*num, els, obj->array, obj->num_el*obj->el_size); - - if (obj->size < obj->num_el + num) { - int num_incs, ret; - - num_incs = ((obj->num_el + num - obj->size) / obj->inc) + 1; - if ((ret = _DynRealloc(obj, num_incs)) != DYN_OK) - return ret; - } - - (void) memmove(obj->array + obj->num_el*obj->el_size, els, - obj->el_size*num); - - obj->num_el += num; - - if (obj->debug) - fprintf(stderr, "dyn: append: done.\n"); - - return DYN_OK; -} - diff --git a/libdyn/dyn_create.c b/libdyn/dyn_create.c deleted file mode 100644 index e5bce99..0000000 --- a/libdyn/dyn_create.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * This file is part of libdyn.a, the C Dynamic Object library. It - * contains the source code for the functions DynCreate() and - * DynDestroy(). - * - * There are no restrictions on this code; however, if you make any - * changes, I request that you document them so that I do not get - * credit or blame for your modifications. - * - * Written by Barr3y Jaspan, Student Information Processing Board (SIPB) - * and MIT-Project Athena, 1989. - */ - -#include - -#include "dynP.h" - -#ifndef DEFAULT_INC -#define DEFAULT_INC 100 -#endif - -static int default_increment = DEFAULT_INC; - -DynObject -DynCreate(int el_size, - int inc) -{ - DynObject obj; - - obj = (DynObject) malloc(sizeof(DynObjectRec)); - if (obj == NULL) - return NULL; - - obj->array = (DynPtr) malloc(0); - obj->el_size = el_size; - obj->num_el = obj->size = 0; - obj->debug = obj->paranoid = 0; - obj->inc = (!! inc) ? inc : default_increment; - - return obj; -} - -int -DynDestroy(DynObject obj) -{ - free(obj->array); - free(obj); - return DYN_OK; -} diff --git a/libdyn/dyn_debug.c b/libdyn/dyn_debug.c deleted file mode 100644 index 95440be..0000000 --- a/libdyn/dyn_debug.c +++ /dev/null @@ -1,25 +0,0 @@ -/* - * This file is part of libdyn.a, the C Dynamic Object library. It - * contains the source code for the function DynDebug(). - * - * There are no restrictions on this code; however, if you make any - * changes, I request that you document them so that I do not get - * credit or blame for your modifications. - * - * Written by Barr3y Jaspan, Student Information Processing Board (SIPB) - * and MIT-Project Athena, 1989. - */ - -#include - -#include "dynP.h" - -int -DynDebug(DynObject obj, - int state) -{ - obj->debug = state; - - fprintf(stderr, "dyn: debug: Debug state set to %d.\n", state); - return DYN_OK; -} diff --git a/libdyn/dyn_delete.c b/libdyn/dyn_delete.c deleted file mode 100644 index 256f49e..0000000 --- a/libdyn/dyn_delete.c +++ /dev/null @@ -1,77 +0,0 @@ -/* - * This file is part of libdyn.a, the C Dynamic Object library. It - * contains the source code for the function DynDelete(). - * - * There are no restrictions on this code; however, if you make any - * changes, I request that you document them so that I do not get - * credit or blame for your modifications. - * - * Written by Barr3y Jaspan, Student Information Processing Board (SIPB) - * and MIT-Project Athena, 1989. - */ - -#include - -#include "dynP.h" - -/* - * Checkers! Get away from that "hard disk erase" button! - * (Stupid dog. He almost did it to me again ...) - */ -int -DynDelete(DynObject obj, - int idx) -{ - if (idx < 0) { - if (obj->debug) - fprintf(stderr, "dyn: delete: bad index %d\n", idx); - return DYN_BADINDEX; - } - - if (idx >= obj->num_el) { - if (obj->debug) - fprintf(stderr, "dyn: delete: Highest index is %d.\n", - obj->num_el); - return DYN_BADINDEX; - } - - if (idx == obj->num_el-1) { - if (obj->paranoid) { - if (obj->debug) - fprintf(stderr, "dyn: delete: last element, zeroing.\n"); - (void) memset(obj->array + idx*obj->el_size, 0, obj->el_size); - } - else { - if (obj->debug) - fprintf(stderr, "dyn: delete: last element, punting.\n"); - } - } - else { - if (obj->debug) - fprintf(stderr, - "dyn: delete: copying %d bytes from %p + %d to + %d.\n", - obj->el_size*(obj->num_el - idx), obj->array, - (idx+1)*obj->el_size, idx*obj->el_size); - - (void) memmove(obj->array + idx*obj->el_size, - obj->array + (idx+1)*obj->el_size, - obj->el_size*(obj->num_el - idx)); - - if (obj->paranoid) { - if (obj->debug) - fprintf(stderr, - "dyn: delete: zeroing %d bytes from %p + %d\n", - obj->el_size, obj->array, - obj->el_size*(obj->num_el - 1)); - (void) memset(obj->array + obj->el_size*(obj->num_el - 1), - 0, obj->el_size); - } - } - - --obj->num_el; - - if (obj->debug) - fprintf(stderr, "dyn: delete: done.\n"); - - return DYN_OK; -} diff --git a/libdyn/dyn_header.c b/libdyn/dyn_header.c deleted file mode 100644 index ffe2c92..0000000 --- a/libdyn/dyn_header.c +++ /dev/null @@ -1,11 +0,0 @@ -/* - * This file is part of libdyn.a, the C Dynamic Object library. It - * contains the source code for the function xxx. - * - * There are no restrictions on this code; however, if you make any - * changes, I request that you document them so that I do not get - * credit or blame for your modifications. - * - * Written by Barr3y Jaspan, Student Information Processing Board (SIPB) - * and MIT-Project Athena, 1989. - */ diff --git a/libdyn/dyn_insert.c b/libdyn/dyn_insert.c deleted file mode 100644 index 4445e02..0000000 --- a/libdyn/dyn_insert.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This file is part of libdyn.a, the C Dynamic Object library. It - * contains the source code for the function DynInsert(). - * - * There are no restrictions on this code; however, if you make any - * changes, I request that you document them so that I do not get - * credit or blame for your modifications. - * - * Written by Barr3y Jaspan, Student Information Processing Board (SIPB) - * and MIT-Project Athena, 1989. - */ - -#include "dynP.h" - -int -DynInsert(DynObject obj, - int idx, - DynPtr els, - int num) - -{ - int ret; - - if (idx < 0 || idx > obj->num_el) { - if (obj->debug) - fprintf(stderr, "dyn: insert: index %d is not in [0,%d]\n", - idx, obj->num_el); - return DYN_BADINDEX; - } - - if (num < 1) { - if (obj->debug) - fprintf(stderr, "dyn: insert: cannot insert %d elements\n", - num); - return DYN_BADVALUE; - } - - if (obj->debug) - fprintf(stderr,"dyn: insert: Moving %d bytes from %p + %d to + %d\n", - (obj->num_el-idx)*obj->el_size, obj->array, - obj->el_size*idx, obj->el_size*(idx+num)); - - if ((ret = _DynResize(obj, obj->num_el + num)) != DYN_OK) - return ret; - - (void) memmove(obj->array + (idx + num), obj->array + idx, - (obj->num_el-idx)*obj->el_size); - - if (obj->debug) - fprintf(stderr, "dyn: insert: Copying %d bytes from %p to %p + %d\n", - obj->el_size*num, els, obj->array, obj->el_size*idx); - - (void) memmove(obj->array + obj->el_size*idx, els, obj->el_size*num); - - obj->num_el += num; - - if (obj->debug) - fprintf(stderr, "dyn: insert: done.\n"); - - return DYN_OK; -} diff --git a/libdyn/dyn_paranoid.c b/libdyn/dyn_paranoid.c deleted file mode 100644 index 1c7b81c..0000000 --- a/libdyn/dyn_paranoid.c +++ /dev/null @@ -1,25 +0,0 @@ -/* - * This file is part of libdyn.a, the C Dynamic Object library. It - * contains the source code for the function DynDebug(). - * - * There are no restrictions on this code; however, if you make any - * changes, I request that you document them so that I do not get - * credit or blame for your modifications. - * - * Written by Barr3y Jaspan, Student Information Processing Board (SIPB) - * and MIT-Project Athena, 1989. - */ - -#include - -#include "dynP.h" - -int -DynParanoid(DynObject obj, int state) -{ - obj->paranoid = state; - - if (obj->debug) - fprintf(stderr, "dyn: paranoid: Paranoia set to %d.\n", state); - return DYN_OK; -} diff --git a/libdyn/dyn_put.c b/libdyn/dyn_put.c deleted file mode 100644 index addeadd..0000000 --- a/libdyn/dyn_put.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * This file is part of libdyn.a, the C Dynamic Object library. It - * contains the source code for the functions DynGet() and DynAdd(). - * - * There are no restrictions on this code; however, if you make any - * changes, I request that you document them so that I do not get - * credit or blame for your modifications. - * - * Written by Barr3y Jaspan, Student Information Processing Board (SIPB) - * and MIT-Project Athena, 1989. - */ - -#include "dynP.h" - -static int DynPut __P((DynObject obj, DynPtr el, int index)); - -DynPtr -DynGet(DynObject obj, - int num) -{ - if (num < 0) { - if (obj->debug) - fprintf(stderr, "dyn: get: bad index %d\n", num); - return NULL; - } - - if (num >= obj->num_el) { - if (obj->debug) - fprintf(stderr, "dyn: get: highest element is %d.\n", - obj->num_el); - return NULL; - } - - if (obj->debug) - fprintf(stderr, "dyn: get: Returning address %p + %d.\n", - obj->array, obj->el_size*num); - - return (DynPtr) obj->array + obj->el_size*num; -} - -int -DynAdd(DynObject obj, - DynPtr el) -{ - int ret; - - ret = DynPut(obj, el, obj->num_el); - if (ret != DYN_OK) - return ret; - - ++obj->num_el; - return ret; -} - -/* - * WARNING! There is a reason this function is not documented in the - * man page. If DynPut used to mutate already existing elements, - * everything will go fine. If it is used to add new elements - * directly, however, the state within the object (such as - * obj->num_el) will not be updated properly and many other functions - * in the library will lose. Have a nice day. - */ -static int -DynPut(DynObject obj, - DynPtr el, - int index) -{ - int ret; - - if (obj->debug) - fprintf(stderr, "dyn: put: Writing %d bytes from %p to %p + %d\n", - obj->el_size, el, obj->array, index*obj->el_size); - - if ((ret = _DynResize(obj, index)) != DYN_OK) - return ret; - - (void) memmove(obj->array + index*obj->el_size, el, obj->el_size); - - if (obj->debug) - fprintf(stderr, "dyn: put: done.\n"); - - return DYN_OK; -} diff --git a/libdyn/dyn_realloc.c b/libdyn/dyn_realloc.c deleted file mode 100644 index 25cf20d..0000000 --- a/libdyn/dyn_realloc.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - * This file is part of libdyn.a, the C Dynamic Object library. It - * contains the source code for the internal function _DynRealloc(). - * - * There are no restrictions on this code; however, if you make any - * changes, I request that you document them so that I do not get - * credit or blame for your modifications. - * - * Written by Barr3y Jaspan, Student Information Processing Board (SIPB) - * and MIT-Project Athena, 1989. - */ - -#include - -#include "dynP.h" - -/* - * Ideally, this function should not be called from outside the - * library. However, nothing will break if it is. - */ -int -_DynRealloc(DynObject obj, - int num_incs) -{ - DynPtr temp; - int new_size_in_bytes; - - new_size_in_bytes = obj->el_size*(obj->size + obj->inc*num_incs); - - if (obj->debug) - fprintf(stderr, - "dyn: alloc: Increasing object by %d bytes (%d incs).\n", - obj->el_size*obj->inc*num_incs, num_incs); - - temp = (DynPtr) realloc(obj->array, new_size_in_bytes); - if (temp == NULL) { - if (obj->debug) - fprintf(stderr, "dyn: alloc: Out of memory.\n"); - return DYN_NOMEM; - } - else { - obj->array = temp; - obj->size += obj->inc*num_incs; - } - - if (obj->debug) - fprintf(stderr, "dyn: alloc: done.\n"); - - return DYN_OK; -} diff --git a/libdyn/dyn_size.c b/libdyn/dyn_size.c deleted file mode 100644 index ea1cc38..0000000 --- a/libdyn/dyn_size.c +++ /dev/null @@ -1,24 +0,0 @@ -/* - * This file is part of libdyn.a, the C Dynamic Object library. It - * contains the source code for the function DynSize(). - * - * There are no restrictions on this code; however, if you make any - * changes, I request that you document them so that I do not get - * credit or blame for your modifications. - * - * Written by Barr3y Jaspan, Student Information Processing Board (SIPB) - * and MIT-Project Athena, 1989. - */ - -#include - -#include "dynP.h" - -int -DynSize(DynObject obj) -{ - if (obj->debug) - fprintf(stderr, "dyn: size: returning size %d.\n", obj->num_el); - - return obj->num_el; -} diff --git a/libdyn/dyntest.c b/libdyn/dyntest.c deleted file mode 100644 index 009a3d9..0000000 --- a/libdyn/dyntest.c +++ /dev/null @@ -1,132 +0,0 @@ -/* - * This file is a (rather silly) demonstration of the use of the - * C Dynamic Object library. It is a also reasonably thorough test - * of the library (except that it only tests it with one data size). - * - * There are no restrictions on this code; however, if you make any - * changes, I request that you document them so that I do not get - * credit or blame for your modifications. - * - * Written by Barr3y Jaspan, Student Information Processing Board (SIPB) - * and MIT-Project Athena, 1989. - */ - -#include -#include - -#include "dyn.h" - -static char random_string[] = "This is a random string."; -static char insert1[] = "This will be put at the beginning."; -static char insert2[] = "(parenthetical remark!) "; -static char insert3[] = " This follows the random string."; - -int -main(int argc, - char **argv) -{ - DynObject obj; - int i, s; - char d, *data; - - obj = DynCreate(sizeof(char), 8); - if (! obj) { - fprintf(stderr, "test: create failed.\n"); - exit(1); - } - - DynDebug(obj, 1); - DynParanoid(obj, 1); - - if (DynGet(obj, -5) || DynGet(obj, 0) || DynGet(obj, 1000)) { - fprintf(stderr, "test: Get did not fail when it should have.\n"); - exit(1); - } - - if (DynDelete(obj, -1) != DYN_BADINDEX || - DynDelete(obj, 0) != DYN_BADINDEX || - DynDelete(obj, 100) != DYN_BADINDEX) { - fprintf(stderr, "test: Delete did not fail when it should have.\n"); - exit(1); - } - - printf("Size of empty object: %d\n", DynSize(obj)); - - for (i=0; i<14; i++) { - d = (char) i; - if (DynAdd(obj, &d) != DYN_OK) { - fprintf(stderr, "test: Adding %d failed.\n", i); - exit(1); - } - } - - if (DynAppend(obj, random_string, strlen(random_string)+1) != DYN_OK) { - fprintf(stderr, "test: appending array failed.\n"); - exit(1); - } - - if (DynDelete(obj, DynHigh(obj) / 2) != DYN_OK) { - fprintf(stderr, "test: deleting element failed.\n"); - exit(1); - } - - if (DynDelete(obj, DynHigh(obj) * 2) == DYN_OK) { - fprintf(stderr, "test: delete should have failed here.\n"); - exit(1); - } - - d = 200; - if (DynAdd(obj, &d) != DYN_OK) { - fprintf(stderr, "test: Adding %d failed.\n", i); - exit(1); - } - - data = (char *) DynGet(obj, 0); - s = DynSize(obj); - for (i=0; i < s; i++) - printf("Element %d is %d.\n", i, (unsigned char) data[i]); - - data = (char *) DynGet(obj, 13); - printf("Element 13 is %d.\n", (unsigned char) *data); - - data = (char *) DynGet(obj, DynSize(obj)); - if (data) { - fprintf(stderr, "DynGet did not return NULL when it should have.\n"); - exit(1); - } - - printf("This should be the random string: \"%s\"\n", - (char *) DynGet(obj, 14)); - - if (DynInsert(obj, -1, "foo", 4) != DYN_BADINDEX || - DynInsert(obj, DynSize(obj) + 1, "foo", 4) != DYN_BADINDEX || - DynInsert(obj, 0, "foo", -1) != DYN_BADVALUE) { - fprintf(stderr, "DynInsert did not fail when it should have.\n"); - exit(1); - } - - if (DynInsert(obj, DynSize(obj) - 2, insert3, strlen(insert3) + - 1) != DYN_OK) { - fprintf(stderr, "DynInsert to end failed.\n"); - exit(1); - } - - if (DynInsert(obj, 19, insert2, strlen(insert2)) != DYN_OK) { - fprintf(stderr, "DynInsert to middle failed.\n"); - exit(1); - } - - if (DynInsert(obj, 0, insert1, strlen(insert1)+1) != DYN_OK) { - fprintf(stderr, "DynInsert to start failed.\n"); - exit(1); - } - - printf("A new random string: \"%s\"\n", - (char *) DynGet(obj, 14 + strlen(insert1) + 1)); - printf("This was put at the beginning: \"%s\"\n", - (char *) DynGet(obj, 0)); - - DynDestroy(obj); - - return 0; -} -- cgit v1.2.3