diff --git a/lib/libc/makebuild b/lib/libc/makebuild new file mode 100644 index 0000000..2362cc7 --- /dev/null +++ b/lib/libc/makebuild @@ -0,0 +1,37 @@ +#! /bin/gsh + +rm -f libc +makelib.apw -w -r -p -l libc gen/*.o +makelib.apw -w -r -p -l libc gno/*.o +makelib.apw -w -r -p -l libc locale/*.o +makelib.apw -w -r -p -l libc stdio/*.o +makelib.apw -w -r -p -l libc stdlib/*.o +makelib.apw -w -r -p -l libc string/*.o +makelib.apw -w -r -p -l libc sys/*.o /src/lib/orcalibs/Source/ORCALib/obj/assert.a + +exit 0 + +set CWD=/src/gno/lib/libc +echo CWD is $CWD + +set DMAKE=dmake + +set d=gen + echo "doing build in" $d; cd $d; $dmake build; cd $CWD +set d=gno + echo "doing build in" $d; cd $d; $dmake build; cd $CWD +set d=locale + echo "doing build in" $d; cd $d; $dmake build; cd $CWD +set d=stdio + echo "doing build in" $d; cd $d; $dmake build; cd $CWD +set d=stdlib + echo "doing build in" $d; cd $d; $dmake build; cd $CWD +# set d=stdtime +# echo "doing build in" $d; cd $d; $dmake build; cd $CWD +set d=string + echo "doing build in" $d; cd $d; $dmake build; cd $CWD +set d=sys + echo "doing build in" $d; cd $d; $dmake build; cd $CWD + +echo "doing build in $CWD" +$dmake build diff --git a/lib/libcontrib/Makefile b/lib/libcontrib/Makefile new file mode 100644 index 0000000..721a4d4 --- /dev/null +++ b/lib/libcontrib/Makefile @@ -0,0 +1,28 @@ +# +# This is the top-level makefile for libcontrib, GNO v2.0.6 +# +# $Id: Makefile,v 1.1 1997/10/03 04:49:40 gdr Exp $ +# + +.INCLUDE: ../../paths.mk +.INCLUDE: ../const.mk + +LIB = libcontrib +OBJS = strarray.o xalloc.o +HEADER = contrib.h +LIBDIR = $(RELEASE_DIR)/usr/lib +INCDIR = $(RELEASE_DIR)/usr/include/gno + +CFLAGS += -I. -O78 + +$(LIB): $(OBJS) $(LIB).r + $(RM) -f $@ + $(MAKELIB) $(MAKELIBFLAGS) -l $@ $(OBJS) + $(CATREZ) -d $(LIB) $(LIB).r + +release: $(LIB) $(HEADER) + $(INSTALL) -d $(LIBDIR) $(INCDIR) + $(INSTALL) $(LIB) $(LIBDIR) + $(INSTALL) $(HEADER) $(INCDIR) + +$(OBJS):: $(HEADER) diff --git a/lib/libcontrib/contrib.h b/lib/libcontrib/contrib.h new file mode 100644 index 0000000..9dd5aec --- /dev/null +++ b/lib/libcontrib/contrib.h @@ -0,0 +1,40 @@ +/* + * $Id: contrib.h,v 1.1 1997/10/03 04:49:40 gdr Exp $ + */ + +#ifndef _CONTRIB_H_ +#define _CONTRIB_H_ + +#ifndef _SYS_TYPES_H_ +#include +#endif + +#ifndef _SYS_CDEFS_H_ +#include +#endif + +/* + * Memory allocation routines + */ + +void * LC_xmalloc __P((size_t)); +void * LC_xrealloc __P((void *, size_t)); +char * LC_xstrdup __P((const char *)); + +/* + * String Array Functions. + */ + +typedef struct LC_StringArrayElem_t { + char ** lc_vec; + int lc_alloced; + int lc_used; +} LC_StringArrayElem_t, *LC_StringArray_t; + +LC_StringArray_t LC_StringArrayNew __P((void)); +void LC_StringArrayAdd __P((LC_StringArray_t, char *)); +void LC_StringArrayDelete __P((LC_StringArray_t, char *)); +void LC_StringArrayClear __P((LC_StringArray_t)); +char * LC_StringArrayCat __P((LC_StringArray_t, int)); + +#endif /* _CONTRIB_H_ */ diff --git a/lib/libcontrib/libcontrib.rez b/lib/libcontrib/libcontrib.rez new file mode 100644 index 0000000..2635117 --- /dev/null +++ b/lib/libcontrib/libcontrib.rez @@ -0,0 +1,31 @@ +/* + * Resources for version and comment + * + * $Id: libcontrib.rez,v 1.1 1997/10/03 04:49:40 gdr Exp $ + */ +#define LIB "lcontrib" +#define DESC "A library of non-standard but still useful subroutines.\n" +#define GNO_VER "GNO v2.0.6" + +#include "Types.rez" + +/* + * Version + */ +resource rVersion (1, purgeable3) { + { 1, 0, 0, /* Version 1.0.0 */ + release, /* development|alpha|beta|final|release */ + 0 }, /* non-final release number */ + verUS, /* Country */ + LIB, /* Program name */ + DESC GNO_VER +}; + + +/* + * Comment + */ +resource rComment (1, purgeable3) { + LIB " v1.0 (September 1997)\n" + DESC GNO_VER +}; diff --git a/lib/libcontrib/strarray.c b/lib/libcontrib/strarray.c new file mode 100644 index 0000000..4f51b85 --- /dev/null +++ b/lib/libcontrib/strarray.c @@ -0,0 +1,188 @@ +/* + * String Array implementation. These routines dynamically handle an + * array of NULL-terminated strings. The array itself is also NULL- + * terminated. + * + * Devin Reade, September 1997. + * + * $Id: strarray.c,v 1.1 1997/10/03 04:49:40 gdr Exp $ + */ +#include +#include +#include +#include + +#define SLOTS_QUANTUM 64 + +/* + * LC_StringArrayNew + * + * Creates and returns a new, empty string array. The vector will be + * allocated, but will have NULL as the first element. + */ + +LC_StringArray_t +LC_StringArrayNew (void) { + LC_StringArray_t result; + + result = LC_xmalloc(sizeof(LC_StringArrayElem_t)); + result->lc_vec = LC_xmalloc(SLOTS_QUANTUM * sizeof(char *)); + (result->lc_vec)[0] = NULL; + result->lc_alloced = SLOTS_QUANTUM; + result->lc_used = 0; + return result; +} + +/* + * LC_StringArrayAdd + * + * Adds a string to the stringArray . Calling this + * with ==NULL has no effect as the array is always NULL-terminated. + */ + +void +LC_StringArrayAdd (LC_StringArray_t array, char *str) { + if (array == NULL) { + errx(1, "LC_StringArrayAdd was passed a NULL first argument"); + } + if (array->lc_used > array->lc_alloced) { + errx(1, "LC_StringArrayAdd: corrupted string array"); + } + + if (str == NULL) { + return; + } + + /* grow the size of the string array, if necessary */ + if (array->lc_alloced - array->lc_used < 2) { + array->lc_alloced+=SLOTS_QUANTUM; + if (array->lc_vec == NULL) { + array->lc_vec = LC_xmalloc(array->lc_alloced * sizeof(char *)); + } else { + array->lc_vec = LC_xrealloc(array->lc_vec, + array->lc_alloced * sizeof(char *)); + } + } + + /* add in the string */ + array->lc_vec[array->lc_used] = LC_xstrdup(str); + array->lc_used++; + array->lc_vec[array->lc_used] = NULL; + return; +} + +#if 0 +/* + * This routine has been disabled for now because it is subject to + * buffer overflow. + */ + +/* + * LC_StringArrayAdd2 + * + * This is like LC_StringArrayAdd, but instead of taking one string, + * it takes printf()-like arguments + */ + +void +LC_StringArrayAdd2 (LC_StringArray_t array, char *format, ...) { + va_list ap; + + va_start(ap,format); + vsprintf(buffer,format,ap); + LC_StringArrayAdd(array,buffer); + va_end(ap); + return; +} +#endif + + +void +LC_StringArrayDelete (LC_StringArray_t array, char *str) { + int i; + + for (i=0; ilc_used; i++) { + if (strcmp(array->lc_vec[i],str)) continue; + + /* found it; free up the memory */ + free(array->lc_vec[i]); + for (; ilc_used; i++) { + array->lc_vec[i]=array->lc_vec[i+1]; + } + break; + } + array->lc_used -= 1; +} + + +/* + * LC_StringArrayClear -- free the memory allocated by LC_StringArrayAdd() + * and reinitialize the associated variables. + */ + +void +LC_StringArrayClear (LC_StringArray_t array) { + int i; + + if (array->lc_used == 0) { + return; + } + if ((array->lc_vec == 0) || (array->lc_alloced == 0)) { + errx(1, "LC_StringArrayClear: corrupted array"); + } + for (i=0; ilc_used; i++) { + free((array->lc_vec)[i]); + } + free(array->lc_vec); + array->lc_vec = NULL; + array->lc_alloced = 0; + array->lc_used = 0; + return; +} + +/* + * LC_StringArrayCat + * + * Concatenate the elements of a LC_StringArray_t into a single character + * string. Return a pointer to the malloc'd string. The LC_StringArray_t + * is not modified. + */ + +char * +LC_StringArrayCat (LC_StringArray_t array, int insertSpace) { + int i, j; + size_t len, len2; + char *result, *p, *q, **qq; + + len = 1; + j = (insertSpace) ? 1 : 0; + for (i=0; ilc_used; i++) { + len += strlen((array->lc_vec)[i]) + j; + } + result = LC_xmalloc(len * sizeof(char)); + *p = *result = '\0'; + j = array->lc_used; + qq = array->lc_vec; + for (i=0; ilc_vec)[i]); + if (insertSpace) { + strcat(result," "); + } +#endif + } + if (len > 1) { + /* dump the extra space at the end of the string */ + result[len-1]='\0'; + } + return result; +} diff --git a/lib/libcontrib/xalloc.c b/lib/libcontrib/xalloc.c new file mode 100644 index 0000000..01b8758 --- /dev/null +++ b/lib/libcontrib/xalloc.c @@ -0,0 +1,46 @@ +/* + * Memory allocation-related routines that call exit(3) if they fail. + * + * Devin Reade, September 1997 + * + * $Id: xalloc.c,v 1.1 1997/10/03 04:49:40 gdr Exp $ + */ + +#include +#include +#include +#include + +void * +LC_xmalloc (size_t size) { + char *result; + + if ((result = malloc(size)) == NULL) { + err(1, "malloc failed"); + exit(EXIT_FAILURE); + } + return (void *) result; +} + +void * +LC_xrealloc (void *ptr, size_t size) { + char *result; + + if ((result = realloc(ptr, size)) == NULL) { + err(1, "realloc failed"); + exit(EXIT_FAILURE); + } + return (void *) result; +} + +char * +LC_xstrdup (const char *str) { + char *result; + + if ((result = strdup(str)) == NULL) { + err(1, "strdup failed"); + exit(EXIT_FAILURE); + } + return result; +} + diff --git a/lib/libutil/libutil.rez b/lib/libutil/libutil.rez new file mode 100644 index 0000000..8251107 --- /dev/null +++ b/lib/libutil/libutil.rez @@ -0,0 +1,30 @@ +/* + * Resources for version and comment + * + * $Id: libutil.rez,v 1.1 1997/10/03 04:47:47 gdr Exp $ + */ + +#define LIB "libutil for GNO" +#define PORTED "Ported from 4.4BSD by Devin Reade." + +#include "Types.rez" + +/* + * Version + */ +resource rVersion (1, purgeable3) { + { 2, 0, 6, /* Version 2.0.6 */ + alpha, /* development|alpha|beta|final|release */ + 1 }, /* non-final release number */ + verUS, /* Country */ + LIB, + PORTED +}; + +/* + * Comment + */ +resource rComment (1, purgeable3) { + LIB "\n" + PORTED +}; diff --git a/lib/liby/liby.rez b/lib/liby/liby.rez new file mode 100644 index 0000000..6bd758d --- /dev/null +++ b/lib/liby/liby.rez @@ -0,0 +1,30 @@ +/* + * Resources for version and comment + * + * $Id: liby.rez,v 1.1 1997/10/03 04:45:43 gdr Exp $ + */ + +#define LIB "liby for GNO" +#define PORTED "Ported from 4.4BSD by Devin Reade." + +#include "Types.rez" + +/* + * Version + */ +resource rVersion (1, purgeable3) { + { 2, 0, 6, /* Version 2.0.6 */ + release, /* development|alpha|beta|final|release */ + 0 }, /* non-final release number */ + verUS, /* Country */ + LIB, + PORTED +}; + +/* + * Comment + */ +resource rComment (1, purgeable3) { + LIB "\n" + PORTED +};