Mercurial > hg > batmud > maputils
changeset 8:a0dd3254e488
Updated th-libs
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 08 Dec 2006 19:30:23 +0000 |
parents | 939e6a6b480b |
children | 3e7eb65281f4 |
files | th_args.h th_string.h th_util.c th_util.h |
diffstat | 4 files changed, 96 insertions(+), 64 deletions(-) [+] |
line wrap: on
line diff
--- a/th_args.h Fri Apr 28 15:41:56 2006 +0000 +++ b/th_args.h Fri Dec 08 19:30:23 2006 +0000 @@ -7,13 +7,14 @@ */ #ifndef _TH_ARGS #define _TH_ARGS -#include <stdio.h> -#include "th_util.h" #ifdef __cplusplus extern "C" { #endif +#include <stdio.h> +#include "th_util.h" + typedef struct { int optID; char_t shortOpt;
--- a/th_string.h Fri Apr 28 15:41:56 2006 +0000 +++ b/th_string.h Fri Dec 08 19:30:23 2006 +0000 @@ -8,14 +8,14 @@ #ifndef _TH_STRING_H #define _TH_STRING_H +#ifdef __cplusplus +extern "C" { +#endif + #include "th_util.h" #include <stdlib.h> #include <ctype.h> -#ifdef __cplusplus -extern "C" { -#endif - /* * Macros */
--- a/th_util.c Fri Apr 28 15:41:56 2006 +0000 +++ b/th_util.c Fri Dec 08 19:30:23 2006 +0000 @@ -35,33 +35,33 @@ char_t *progName, char_t *progFullName, char_t *progVersion, char_t *progAuthor, char_t *progLicense) { - /* Free previous values */ - if (progName) - th_prog_name = progName; - else - th_prog_name = TH_PROG_NAME; - - if (progFullName) - th_prog_fullname = progFullName; - else - th_prog_fullname = TH_PROG_FULLNAME; - - if (progVersion) - th_prog_version = progVersion; + /* Free previous values */ + if (progName) + th_prog_name = progName; else - th_prog_version = TH_PROG_VERSION; - - if (progAuthor) - th_prog_author = progAuthor; - else - th_prog_author = TH_PROG_AUTHOR; + th_prog_name = TH_PROG_NAME; - if (progLicense) - th_prog_license = progLicense; - else - th_prog_license = TH_PROG_LICENSE; - - th_isInitialized = TRUE; + if (progFullName) + th_prog_fullname = progFullName; + else + th_prog_fullname = TH_PROG_FULLNAME; + + if (progVersion) + th_prog_version = progVersion; + else + th_prog_version = TH_PROG_VERSION; + + if (progAuthor) + th_prog_author = progAuthor; + else + th_prog_author = TH_PROG_AUTHOR; + + if (progLicense) + th_prog_license = progLicense; + else + th_prog_license = TH_PROG_LICENSE; + + th_isInitialized = TRUE; } @@ -70,45 +70,41 @@ */ void THERR(const char_t *pcFormat, ...) { - va_list ap; - assert(th_isInitialized); + va_list ap; + assert(th_isInitialized); - va_start(ap, pcFormat); - fprintf(stderr, "%s: ", th_prog_name); - vfprintf(stderr, pcFormat, ap); - va_end(ap); + va_start(ap, pcFormat); + fprintf(stderr, "%s: ", th_prog_name); + vfprintf(stderr, pcFormat, ap); + va_end(ap); } void THMSG(int verbLevel, const char_t *pcFormat, ...) { - va_list ap; - assert(th_isInitialized); - - /* Check if the current verbosity level is enough */ - if (th_verbosityLevel >= verbLevel) - { - /* Print message */ - va_start(ap, pcFormat); - fprintf(stderr, "%s: ", th_prog_name); - vfprintf(stderr, pcFormat, ap); - va_end(ap); + va_list ap; + assert(th_isInitialized); + + /* Check if the current verbosity level is enough */ + if (th_verbosityLevel >= verbLevel) { + va_start(ap, pcFormat); + fprintf(stderr, "%s: ", th_prog_name); + vfprintf(stderr, pcFormat, ap); + va_end(ap); } } void THPRINT(int verbLevel, const char_t *pcFormat, ...) { - va_list ap; - assert(th_isInitialized); + va_list ap; + assert(th_isInitialized); - /* Check if the current verbosity level is enough */ - if (th_verbosityLevel >= verbLevel) - { - /* Print message */ - va_start(ap, pcFormat); - vfprintf(stderr, pcFormat, ap); - va_end(ap); + /* Check if the current verbosity level is enough */ + if (th_verbosityLevel >= verbLevel) { + va_start(ap, pcFormat); + vfprintf(stderr, pcFormat, ap); + va_end(ap); } } @@ -120,19 +116,19 @@ */ void *th_malloc(size_t l) { - return malloc(l); + return malloc(l); } void *th_calloc(size_t n, size_t l) { - return calloc(n, l); + return calloc(n, l); } void *th_realloc(void *p, size_t l) { - return realloc(p, l); + return realloc(p, l); } @@ -143,3 +139,19 @@ */ if (p) free(p); } + + +#ifndef HAVE_MEMSET +void *th_memset(void *p, int c, size_t n) +{ + char *dp; + + dp = (char *) p; + while (n--) { + *dp = (char) c; + n--; + } + + return p; +} +#endif
--- a/th_util.h Fri Apr 28 15:41:56 2006 +0000 +++ b/th_util.h Fri Dec 08 19:30:23 2006 +0000 @@ -7,15 +7,28 @@ */ #ifndef _TH_UTIL_H #define _TH_UTIL_H + +#ifdef __cplusplus +extern "C" { +#endif + #include "th_types.h" #include <stdarg.h> #include <stdlib.h> -#ifndef TH_HAVE_NO_ASSERT +#ifndef HAVE_NO_ASSERT #include <assert.h> #endif -#ifdef __cplusplus -extern "C" { +#ifdef HAVE_STRING_H +#include <string.h> +#else +#ifdef HAVE_STRINGS_H +#include <strings.h> +#endif +#endif + +#ifdef HAVE_MEMORY_H +#include <memory.h> #endif /* @@ -34,7 +47,7 @@ #endif /* Replacement for assert() */ -#ifdef TH_HAVE_NO_ASSERT +#ifdef HAVE_NO_ASSERT #ifdef NDEBUG #define assert(NEXPR) /* stub */ #else @@ -66,6 +79,12 @@ void * th_realloc(void *, size_t); void th_free(void *); +#ifdef HAVE_MEMSET +#define th_memset memset +#else +void *th_memset(void *, int, size_t); +#endif + #ifdef __cplusplus } #endif