1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "wv.h"
int wvGetEmpty_PLCF(U32 **cps,U32 *nocps,U32 offset,U32 len,FILE *fd)
{
U32 i;
if (len == 0)
{
*cps = NULL;
*nocps = 0;
}
else
{
*nocps=len/4;
*cps = (U32 *) malloc(*nocps * sizeof(U32));
if (*cps == NULL)
{
wvError(("NO MEM 3, failed to alloc %d bytes\n",*nocps * sizeof(U32)));
return(1);
}
fseek(fd,offset,SEEK_SET);
for(i=0;i<*nocps;i++)
(*cps)[i] = read_32ubit(fd);
}
return(0);
}
void wvFree(void *ptr)
{
if (ptr != NULL)
free(ptr);
ptr = NULL;
}
/*
If the
second most significant bit is clear, then this indicates the actual file
offset of the unicode character (two bytes). If the second most significant
bit is set, then the actual address of the codepage-1252 compressed version
of the unicode character (one byte), is actually at the offset indicated by
clearing this bit and dividing by two.
*/
/*
flag = 1 means that this is a one byte char, 0 means that this is a type
byte char
*/
U32 wvNormFC(U32 fc,int *flag)
{
if (fc & 0x40000000UL)
{
fc = fc & 0xbfffffffUL;
fc = fc/2;
if (flag) *flag = 1;
}
else
if (flag) *flag = 0;
return(fc);
}
U16 wvGetChar(FILE *fd,U8 chartype)
{
if (chartype == 1)
return(getc(fd));
else
return(read_16ubit(fd));
return(0);
}
int wvIncFC(U8 chartype)
{
if (chartype == 1)
return(1);
return(2);
}
int wvStrlen(const char *str)
{
if (str == NULL)
return(0);
return(strlen(str));
}
char *wvStrcat(char *dest, const char *src)
{
if (src != NULL)
return(strcat(dest,src));
else
return(dest);
}
void wvAppendStr(char **orig,const char *add)
{
int pos;
wvTrace(("got this far\n"));
pos = wvStrlen(*orig);
wvTrace(("len is %d %d\n",pos,wvStrlen(add)));
(*orig) = (char *)realloc(*orig,pos+wvStrlen(add)+1);
(*orig)[pos] = '\0';
wvTrace(("3 test str of %s\n",*orig));
wvStrcat(*orig,add);
wvTrace(("3 test str of %s\n",*orig));
}
void wvStrToUpper(char *str)
{
int i;
if (str == NULL)
return;
for(i=0;i<wvStrlen(str);i++)
str[i] = toupper(str[i]);
}
|