home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume36
/
formes
/
part02
/
exstr.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-04-01
|
5KB
|
261 lines
/*
* Copyright (C) 1992-1993 Jeffrey Chilton
*
* Permission is granted to anyone to make or distribute copies of
* this program, in any medium, provided that the copyright notice
* and permission notice are preserved, and that the distributor
* grants the recipient permission for further redistribution as
* permitted by this notice.
*
* Author's E-mail address: 172-9221@mcimail.com
*
*/
static char *whatstring = "@(#)exstr.c 2.4 JWC";
#include <string.h>
#include <malloc.h>
#include "class.h"
#include "exstr.h"
/* Special character translation */
#define NLETTERS 10
#define NMARKS 5
char Letters[NLETTERS + 1] = "ACEIOaceio";
char Marks[NMARKS + 1] = "`'^,~";
#if DOS
/* IBM/PC (note idiotic display adapter lacks most accented capitals) */
unsigned char MarkedLetters[NLETTERS][NMARKS] =
{
/* ` ' ^ , ~ */
/* ---- ---- ---- ---- ---- */
/* A */ 'A', 'A', 'A', 0, 0,
/* C */ 0, 0, 0, 0x80, 0,
/* E */ 'E', 0x90, 'E', 0, 0,
/* I */ 'I', 'I', 'I', 0, 'I',
/* O */ 'O', 'O', 'O', 0, 0,
/* a */ 0x85, 0xA0, 0x83, 0, 0,
/* c */ 0, 0, 0, 0x87, 0,
/* e */ 0x8A, 0x82, 0x88, 0, 0,
/* i */ 0x8D, 0xA1, 0x8C, 0, 0x8B,
/* o */ 0x95, 0xA2, 0x93, 0, 0
};
#else
/* Sun/SPARC (ANSI standard extended characters) */
unsigned char MarkedLetters[NLETTERS][NMARKS] =
{
/* ` ' ^ , ~ */
/* --- --- --- --- --- */
/* A */ 192, 193, 194, 0, 0,
/* C */ 0, 0, 0, 199, 0,
/* E */ 200, 201, 202, 0, 0,
/* I */ 204, 205, 206, 0, 207,
/* O */ 210, 211, 212, 0, 0,
/* a */ 224, 225, 226, 0, 0,
/* c */ 0, 0, 0, 231, 0,
/* e */ 232, 233, 234, 0, 0,
/* i */ 236, 237, 238, 0, 239,
/* o */ 242, 243, 244, 0, 0
};
#endif
/* ExtendString_newFromString - convert from external form */
ExtendString *
ExtendString_newFromString(str)
char *str;
{
register int i, j;
ExtendString *result;
ExtendString *dest;
unsigned char c;
char *t, *u;
if (str[0] == '\0')
{
result = (ExtendString *)"";
goto out;
}
result = (ExtendString *)malloc(1 + strlen(str));
dest = result;
while (*str)
{
t = strchr(Letters, *str);
if (t && *(str + 1))
{
u = strchr(Marks, *(str + 1));
if (u)
{
c = MarkedLetters[t - Letters][u - Marks];
if (c)
{
*dest++ = c;
str += 2;
continue;
}
}
}
*dest++ = *str++;
}
*dest = '\0';
out:
return result;
}
/* ExtendString_externalFormat - convert to external form */
char *
ExtendString_externalFormat(self)
ExtendString *self;
{
register int i, j;
int length, found;
ExtendString *t;
char *result;
char *out;
length = 0;
t = self;
while (*t)
{
found = FALSE;
for (i = 0; i < NLETTERS; i++)
{
for (j = 0; j < NMARKS; j++)
{
if (MarkedLetters[i][j] == *t)
{
found = TRUE;
break;
}
}
if (found)
{
break;
}
}
length += found ? 2 : 1;
t++;
}
result = (char *)malloc(1 + length);
out = result;
t = self;
while (*t)
{
found = FALSE;
for (i = 0; i < NLETTERS; i++)
{
for (j = 0; j < NMARKS; j++)
{
if (MarkedLetters[i][j] == *t)
{
t++;
found = TRUE;
*out++ = Letters[i];
*out++ = Marks[j];
break;
}
}
if (found)
{
break;
}
}
if (found)
{
continue;
}
*out++ = *t++;
}
*out = '\0';
return result;
}
/* ExtendString_compareSansAccent - is external form close enough */
int
ExtendString_compareSansAccent(self, str)
ExtendString *self;
char *str;
{
register int i;
register int r, c;
ExtendString *vert;
int length;
int found;
int rc;
rc = strcmp((char *)self, str);
if (rc == 0)
{
goto out;
}
vert = ExtendString_newFromString(str);
rc = strcmp((char *)self, (char *)vert);
ExtendString_destroy(vert);
if (rc == 0)
{
goto out;
}
length = strlen((char *)self) + 1;
for (i = 0; i < length; i++)
{
if (self[i] == str[i])
{
continue;
}
found = FALSE;
for (r = 0; r < NLETTERS; r++)
{
for (c = 0; c < NMARKS; c++)
{
if (MarkedLetters[r][c] == self[i])
{
found = TRUE;
break;
}
}
if (found)
{
break;
}
}
if (!found || str[i] != Letters[r])
{
rc = 1;
goto out;
}
}
rc = 0;
out:
return rc;
}