diff --git a/libfatptr/Makefile b/libfatptr/Makefile new file mode 100644 index 0000000..49e95d4 --- /dev/null +++ b/libfatptr/Makefile @@ -0,0 +1 @@ +libfatptr.o: diff --git a/libfatstr/libfatstr.c b/libfatptr/libfatptr.c similarity index 51% rename from libfatstr/libfatstr.c rename to libfatptr/libfatptr.c index 9e4e27e..753327f 100644 --- a/libfatstr/libfatstr.c +++ b/libfatptr/libfatptr.c @@ -1,31 +1,31 @@ #include /* free(3), malloc(3), realloc(3) */ #include /* strncpy(3), size_t */ -#include "libfatstr.h" +#include "libfatptr.h" /* quick and dirty ASCII edition */ /* Size by which to grow memory allocations. */ -static size_t FatStr_growinterval = 100; /* in sizeof chars */ +static size_t FatPtr_growinterval = 100; /* in sizeof chars */ -struct FatStr * -FatStr_append(struct FatStr *p, FatStr_scalar_t c){ - FatStr_vector_t t; +struct FatPtr * +FatPtr_append(struct FatPtr *p, FatPtr_scalar_t c){ + FatPtr_vector_t t; if(p == NULL || (p->s + (sizeof *(p->v)) > p->a - && FatStr_grow(p, FatStr_growinterval) == NULL)) + && FatPtr_grow(p, FatPtr_growinterval) == NULL)) return NULL; (p->v)[(p->s)++] = c; return p; } -struct FatStr * -FatStr_construct(struct FatStr *p){ +struct FatPtr * +FatPtr_construct(struct FatPtr *p){ - return FatStr_grow(FatStr_initialize(p), FatStr_growinterval); + return FatPtr_grow(FatPtr_initialize(p), FatPtr_growinterval); } char * -FatStr_convert(struct FatStr *p){ +FatPtr_convert(struct FatPtr *p){ char *r; /* allocation might be wrong */ @@ -35,19 +35,19 @@ FatStr_convert(struct FatStr *p){ ; } -struct FatStr * -FatStr_destruct(struct FatStr *p){ +struct FatPtr * +FatPtr_destruct(struct FatPtr *p){ if(p != NULL){ free(p->v); - FatStr_initialize(p); + FatPtr_initialize(p); } return NULL; } -struct FatStr * -FatStr_grow(struct FatStr *p, size_t units){ - FatStr_vector_t t; +struct FatPtr * +FatPtr_grow(struct FatPtr *p, size_t units){ + FatPtr_vector_t t; if(p == NULL || (t = realloc(p->v, p->a + units)) == NULL) return NULL; @@ -56,8 +56,8 @@ FatStr_grow(struct FatStr *p, size_t units){ return p; } -struct FatStr * -FatStr_initialize(struct FatStr *p){ +struct FatPtr * +FatPtr_initialize(struct FatPtr *p){ if(p != NULL){ p->a = 0; @@ -67,6 +67,6 @@ FatStr_initialize(struct FatStr *p){ return p; } -struct FatStr * -FatStr_trimfront(struct FatStr *p, size_t units){ +struct FatPtr * +FatPtr_trimfront(struct FatPtr *p, size_t units){ } diff --git a/libfatptr/libfatptr.h b/libfatptr/libfatptr.h new file mode 100644 index 0000000..a2fcbdd --- /dev/null +++ b/libfatptr/libfatptr.h @@ -0,0 +1,40 @@ +/* #include /* size_t */ + +#if !defined FatPtr_size_t +# define FatPtr_size_t size_t +#endif +#if !defined FatPtr_scalar_t +# define FatPtr_scalar_t int +#endif +#define FatPtr_vector_t FatPtr_scalar_t * + +struct FatPtr{ + FatPtr_size_t a; /* allocation in sizeof char */ + FatPtr_size_t s; /* actual size in sizeof *v */ + FatPtr_vector_t v; /* vector */ +}; + +/* FatPtr_append + * - FatPtr *p: object to which to append + * - FatPtr_scalar_t c: scalar to be appended + * Returns NULL if the operation failed (due to malloc(3)) or if p was NULL. + * Otherwise returns p. */ +struct FatPtr *FatPtr_append(struct FatPtr *p, FatPtr_scalar_t c); + +struct FatPtr *FatPtr_construct(struct FatPtr *p); + +/* FatPtr_convert + * - FatPtr *p: object to convert + * Returns NULL if the operation failed (due to malloc(3)) or if p was NULL. + * Otherwise returns a malloc(3)d char * with the current content of p, which + * should be free(3)d when no longer in use. */ +char *FatPtr_convert(struct FatPtr *p); + +/* FatPtr_destruct + * - FatPtr *p: object to destruct + * Returns NULL. */ +struct FatPtr *FatPtr_destruct(struct FatPtr *p); + +struct FatPtr *FatPtr_grow(struct FatPtr *p, size_t units); +struct FatPtr *FatPtr_initialize(struct FatPtr *p); +struct FatPtr *FatPtr_trimfront(struct FatPtr *p, size_t units); diff --git a/libfatstr/Makefile b/libfatstr/Makefile deleted file mode 100644 index fc93cd7..0000000 --- a/libfatstr/Makefile +++ /dev/null @@ -1 +0,0 @@ -libfatstr.o: diff --git a/libfatstr/libfatstr.h b/libfatstr/libfatstr.h deleted file mode 100644 index f6d0c00..0000000 --- a/libfatstr/libfatstr.h +++ /dev/null @@ -1,37 +0,0 @@ -/* #include /* size_t */ -/* These definitions aren't set in stone. */ -typedef size_t FatStr_size_t; -typedef int FatStr_scalar_t; -typedef FatStr_scalar_t * FatStr_vector_t; - -/* This definition is dependable. */ -struct FatStr{ - FatStr_size_t a; /* allocation in sizeof char */ - FatStr_size_t s; /* actual size in sizeof *v */ - FatStr_vector_t v; /* vector */ -}; - -/* FatStr_append - * - FatStr *p: object to which to append - * - FatStr_scalar_t c: scalar to be appended - * Returns NULL if the operation failed (due to malloc(3)) or if p was NULL. - * Otherwise returns p. */ -struct FatStr *FatStr_append(struct FatStr *p, FatStr_scalar_t c); - -struct FatStr *FatStr_construct(struct FatStr *p); - -/* FatStr_convert - * - FatStr *p: object to convert - * Returns NULL if the operation failed (due to malloc(3)) or if p was NULL. - * Otherwise returns a malloc(3)d char * with the current content of p, which - * should be free(3)d when no longer in use. */ -char *FatStr_convert(struct FatStr *p); - -/* FatStr_destruct - * - FatStr *p: object to destruct - * Returns NULL. */ -struct FatStr *FatStr_destruct(struct FatStr *p); - -struct FatStr *FatStr_grow(struct FatStr *p, size_t units); -struct FatStr *FatStr_initialize(struct FatStr *p); -struct FatStr *FatStr_trimfront(struct FatStr *p, size_t units);