Commit 906ec8a0 authored by Bjorn Reese's avatar Bjorn Reese

Upgraded to trio baseline 1.4

parent 570ff08f
......@@ -22,7 +22,7 @@
static const char rcsid[] = "@(#)$Id$";
#if defined(unix) || defined(__xlC__)
#if defined(unix) || defined(__xlC__) || defined(__QNX__)
# define PLATFORM_UNIX
#elif defined(WIN32) || defined(_WIN32)
# define PLATFORM_WIN32
......@@ -36,6 +36,7 @@ static const char rcsid[] = "@(#)$Id$";
#include "strio.h"
#include <string.h>
#include <locale.h>
#include <ctype.h>
#include <stdarg.h>
#include <time.h>
......@@ -61,8 +62,13 @@ static const char rcsid[] = "@(#)$Id$";
# define USE_STRCASECMP
# define USE_STRNCASECMP
# define USE_STRERROR
# if defined(__QNX__)
# define strcasecmp(x,y) stricmp(x,y)
# define strncasecmp(x,y,n) strnicmp(x,y,n)
# endif
#elif defined(PLATFORM_WIN32)
# define USE_STRCMPI
# define USE_STRCASECMP
# define strcasecmp(x,y) strcmpi(x,y)
#endif
/*************************************************************************
......@@ -101,7 +107,7 @@ char *StrDuplicate(const char *source)
assert(VALID(source));
target = (char *)malloc(StrLength(source) + 1);
target = StrAlloc(StrLength(source) + 1);
if (target)
{
StrCopy(target, source);
......@@ -126,7 +132,7 @@ char *StrDuplicateMax(const char *source, size_t max)
{
len = max;
}
target = (char *)malloc(len);
target = StrAlloc(len);
if (target)
{
StrCopyMax(target, len, source);
......@@ -146,8 +152,6 @@ int StrEqual(const char *first, const char *second)
{
#if defined(USE_STRCASECMP)
return (0 == strcasecmp(first, second));
#elif defined(USE_STRCMPI)
return (0 == strcmpi(first, second));
#else
while ((*first != NIL) && (*second != NIL))
{
......@@ -194,6 +198,21 @@ int StrEqualCaseMax(const char *first, size_t max, const char *second)
return FALSE;
}
/*************************************************************************
* StrEqualLocale
*/
int StrEqualLocale(const char *first, const char *second)
{
assert(VALID(first));
assert(VALID(second));
#if defined(LC_COLLATE)
return (strcoll(first, second) == 0);
#else
return StrEqual(first, second);
#endif
}
/*************************************************************************
* StrEqualMax
*/
......@@ -293,7 +312,7 @@ int StrMatch(char *string, char *pattern)
{
return (NIL == *pattern);
}
if ((toupper(*string) != toupper(*pattern))
if ((toupper((int)*string) != toupper((int)*pattern))
&& ('?' != *pattern))
{
return FALSE;
......@@ -435,9 +454,9 @@ double StrToDouble(const char *source, const char **endp)
while (isxdigit((int)*source))
{
integer *= 16;
integer += (isdigit((int)*source) ? (*source - '0') :
(isupper((int)*source) ? (*source - 'A') :
(*source - 'a')));
integer += (isdigit((int)*source)
? (*source - '0')
: 10 + (toupper((int)*source) - 'A'));
source++;
}
if (*source == '.')
......@@ -446,9 +465,9 @@ double StrToDouble(const char *source, const char **endp)
while (isxdigit((int)*source))
{
fraction *= 16;
fraction += (isdigit((int)*source) ? (*source - '0') :
(isupper((int)*source) ? (*source - 'A') :
(*source - 'a')));
fraction += (isdigit((int)*source)
? (*source - '0')
: 10 + (toupper((int)*source) - 'A'));
fracdiv *= 16;
source++;
}
......@@ -554,7 +573,7 @@ int StrToUpper(char *target)
while (NIL != *target)
{
*target = toupper(*target);
*target = toupper((int)*target);
target++;
i++;
}
......
......@@ -18,13 +18,20 @@
#ifndef TRIO_STRIO_H
#define TRIO_STRIO_H
#if !(defined(DEBUG) || defined(NDEBUG))
# define NDEBUG
#endif
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#ifndef DEBUG
# define NDEBUG
#ifndef STRIO_MALLOC
# define STRIO_MALLOC(n) malloc(n)
#endif
#ifndef STRIO_FREE
# define STRIO_FREE(x) free(x)
#endif
#include <assert.h>
/*
* StrAppend(target, source)
......@@ -129,13 +136,13 @@ enum {
};
#if !defined(DEBUG) || defined(__DECC)
#define StrAlloc(n) (char *)STRIO_MALLOC(n)
#define StrAppend(x,y) strcat((x), (y))
#define StrAlloc(n) ((char *)calloc(1, (n)))
#define StrContains(x,y) (0 != strstr((x), (y)))
#define StrCopy(x,y) strcpy((x), (y))
#define StrFree(x) free((x))
#define StrIndex(x,y) strchr((x), (y))
#define StrIndexLast(x,y) strrchr((x), (y))
#define StrFree(x) STRIO_FREE(x)
#define StrLength(x) strlen((x))
#define StrSubstring(x,y) strstr((x), (y))
#define StrTokenize(x,y) strtok((x), (y))
......@@ -151,13 +158,13 @@ enum {
* so it will use the un-asserted functions above for the
* debugging case too.
*/
#define StrAlloc(n) \
(assert((n) > 0),\
(char *)STRIO_MALLOC(n))
#define StrAppend(x,y) \
(assert((x) != NULL),\
assert((y) != NULL),\
strcat((x), (y)))
#define StrAlloc(n) \
(assert((n) > 0),\
((char *)calloc(1, (n))))
#define StrContains(x,y) \
(assert((x) != NULL),\
assert((y) != NULL),\
......@@ -174,7 +181,7 @@ enum {
strrchr((x), (c)))
#define StrFree(x) \
(assert((x) != NULL),\
free((x)))
STRIO_FREE(x))
#define StrLength(x) \
(assert((x) != NULL),\
strlen((x)))
......@@ -204,6 +211,7 @@ char *StrDuplicateMax(const char *source, size_t max);
int StrEqual(const char *first, const char *second);
int StrEqualCase(const char *first, const char *second);
int StrEqualCaseMax(const char *first, size_t max, const char *second);
int StrEqualLocale(const char *first, const char *second);
int StrEqualMax(const char *first, size_t max, const char *second);
const char *StrError(int);
size_t StrFormatDateMax(char *target, size_t max, const char *format, const struct tm *datetime);
......
This diff is collapsed.
......@@ -32,6 +32,15 @@
#if !defined(WITHOUT_TRIO)
#ifdef __cplusplus
extern "C" {
#endif
/* make utility and C++ compiler in Windows NT fails to find this symbol */
#if defined(WIN32) && !defined(isascii)
# define isascii ((unsigned)(x) < 0x80)
#endif
/*
* Error codes.
*
......@@ -44,7 +53,7 @@ enum {
TRIO_EDBLREF = 4,
TRIO_EGAP = 5,
TRIO_ENOMEM = 6,
TRIO_ERANGE = 7,
TRIO_ERANGE = 7
};
/* Error macros */
......@@ -181,6 +190,10 @@ int trio_sscanfv(const char *buffer, const char *format, void **args);
#define StrFormatAlloc trio_aprintf
#define StrFormatAppendMax trio_snprintfcat
#endif /* TRIO_IGNORE */
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* WITHOUT_TRIO */
#endif /* TRIO_TRIO_H */
......@@ -26,16 +26,49 @@
#ifndef TRIO_TRIOP_H
#define TRIO_TRIOP_H
#if defined(__STDC__) && (__STDC_VERSION__ >= 199901L)
# define TRIO_C99
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef TRIO_C99
# define TRIO_C99 1
#endif
#ifndef TRIO_BSD
# define TRIO_BSD 1
#endif
#ifndef TRIO_GNU
# define TRIO_GNU 1
#endif
#ifndef TRIO_MISC
# define TRIO_MISC 1
#endif
#ifndef TRIO_UNIX98
# define TRIO_UNIX98 1
#endif
#ifndef TRIO_MICROSOFT
# define TRIO_MICROSOFT 1
#endif
#ifndef TRIO_EXTENSION
# define TRIO_EXTENSION 1
#endif
#ifndef TRIO_WIDECHAR
# define TRIO_WIDECHAR 0
#endif
#ifndef TRIO_ERRORS
# define TRIO_ERRORS 1
#endif
#define TRIO_BSD
#define TRIO_GNU
#define TRIO_MISC
#define TRIO_UNIX98
#define TRIO_EXTENSION
#define TRIO_ERRORS
#ifndef TRIO_MALLOC
# define TRIO_MALLOC(n) malloc(n)
#endif
#ifndef TRIO_REALLOC
# define TRIO_REALLOC(x,n) realloc((x),(n))
#endif
#ifndef TRIO_FREE
# define TRIO_FREE(x) free(x)
#endif
typedef int (*trio_callback_t)(void *ref);
......@@ -76,7 +109,7 @@ int trio_get_quote(void *ref); /* ' */
void trio_set_quote(void *ref, int is_quote);
int trio_get_upper(void *ref);
void trio_set_upper(void *ref, int is_upper);
#if defined(TRIO_C99)
#if TRIO_C99
int trio_get_largest(void *ref); /* j */
void trio_set_largest(void *ref, int is_largest);
int trio_get_ptrdiff(void *ref); /* t */
......@@ -98,4 +131,8 @@ void trio_print_double(void *ref, double number);
void trio_print_string(void *ref, char *string);
void trio_print_pointer(void *ref, void *pointer);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* TRIO_TRIOP_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment