
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "utypes.h"
#include "umemory.h"
#define b9D
#include "ustring.h"

int i6M(STRPTR s)
{
size_t len = strlen(s);
int ch = 0;
if (len)
{
ch = s[len - 1];
}
else
{
ch = 0;
}
return ch;
}

STRPTR q6CD(j9B s0Q, STRPTR file, ULONG line)
{
STRPTR q8Y = NULL;
if (s0Q)
{

#if k4E
q8Y = (STRPTR) z3V(strlen(s0Q) + 1, file, line);
#else
q8Y = (STRPTR) e0C(strlen(s0Q) + 1);
#endif
if (q8Y) 
strcpy(q8Y, s0Q); 
}
return (q8Y); 
}

STRPTR g8I(STRPTR s)
{
STRPTR c6Wd = s;
if (s)
for (; *s != '\0'; s++)
*s = toupper(*s);
return c6Wd;
}

int z1T(j9B s1, j9B s2)
{
#define g2Q 1
#if !g2Q
int z3Z; 
#endif
unsigned char c1, c2; 
size_t i = 0; 
do
{
c1 = toupper(s1[i]);
c2 = toupper(s2[i]);
i++;
}
while (c1 && c2 && (c1 == c2));
#if g2Q
return (c2 - c1);
#else
if (c1 < c2)
z3Z = -1; 
else if (c1 > c2)
z3Z = +1; 
else
z3Z = 0; 
return (z3Z); 
#endif
}

int a2Qp(j9B s1, j9B s2, size_t n)
{
int z3Z; 
unsigned char c1, c2; 
size_t i = 0; 
do
{
c1 = toupper(s1[i]);
c2 = toupper(s2[i]);
i++;
}
while (c1 && c2 && (c1 == c2) && (i < n));
if (c1 < c2)
z3Z = -1; 
else if (c1 > c2)
z3Z = +1; 
else
z3Z = 0; 
return (z3Z); 
}

STRPTR u4C(j9B s1, j9B s2)
{
const char *c1;
const char *c2;
do
{
c1 = s1;
c2 = s2;
while (*c1 != '\0' && (toupper(c1[0]) == toupper(c2[0])))
{
c1++;
c2++;
}
if (*c2 == '\0')
{
return (char *) s1;
}
}
while (*s1++ != '\0');
return NULL;
}

void x1P(STRPTR s, STRPTR file, ULONG line)
{
#if k4E
g4G(s, file, line);
#else
g2I(s);
#endif
}

void n9H(STRPTR * s0Q, j9B q8Y, STRPTR file, ULONG line)
{
#if k4E
x1P(*s0Q, file, line); 
*s0Q = q6CD(q8Y, file, line); 
#else
g2I(*s0Q); 
*s0Q = c2Y(q8Y); 
#endif
}

STRPTR t1P(const char ch)
{
static char g8S[2]; 
g8S[0] = ch;
g8S[1] = '\0';
return g8S;
}

STRPTR y6K(j9B str, j9B set)
{
size_t i;
STRPTR result = NULL;
if (str)
{
i = strlen(str) - 1;
while ((i) && (strchr(set, str[i]) == NULL))
i--;
if (strchr(set, str[i]))
result = (STRPTR) & (str[i]);
}
return result;
}

BOOL n7N(STRPTR s, LONG * num)
{
BOOL w4E = FALSE;
errno = 0;
*num = strtol(s, NULL, 10);
if (errno == 0)
{
w4E = TRUE;
}
return w4E;
}

STRPTR v7J(LONG num)
{
static char q8S[10]; 
STRPTR z5Jo = NULL;
if (sprintf(q8S, "%d", (int) num))
{
z5Jo = q8S;
}
return z5Jo;
}

LONG t9LS(STRPTR str, STRPTR set, char x1F, BYTE n7D)
{
STRPTR s = c2Y(set);
LONG r3N = 0;
if (s)
{
STRPTR t3Z = strtok(s, t1P(x1F));
LONG count = 1;
while (!r3N && t3Z)
{
if (n7D & c2U)
{
if (!z1T(str, t3Z))
r3N = count;
}
else if (!strcmp(str, t3Z))
r3N = count;
count++;
t3Z = strtok(NULL, t1P(x1F));
}
f1LS(s);
}
else
r3N = -1;
return (r3N);
}
