Súbor: [Platon] / cpdf / parse.c (stiahnutie)
Revízia 1.4, Sat Sep 14 12:42:40 2002 UTC (21 years, 6 months ago) by lynx
Zmeny od 1.3: +47 -10
[lines]
Added hex() und strlento() functions.
Added parse.h to repository.
Added filter() function.
Linking to zlib dynamicaly.
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* function compute number of locations of char c from buffer to character e
*/
int strlenc(char *buffer, char c, char to)
{
register int i = 0;
register char *p = buffer;
while (*p && *p != to) {
if (*p == c)
i++;
p++;
}
return i;
}
/* function compute lenght of string to char e */
int strlento(register char *buffer, char e)
{
register int i = 0;
register char *p = buffer;
register char to = e;
while (*p && *p != to)
i++;
return i;
}
/* convert hex to bin */
char *hex(char *buffer)
{
char *hex_array;
char num[2];
int i;
if (*buffer != '<')
return NULL;
i = strlento(buffer + 1, '>') / 2 * sizeof(char);
hex_array = (char *) malloc(i);
while (*buffer != '>') {
num[0] = *buffer;
if (*(buffer + 1) == '>')
num[1] = '0';
else {
num[1] = *(buffer + 1);
buffer += 2;
}
*hex_array = (char) strtoul((char *) &num, NULL, 16);
hex_array++;
}
return hex_array;
}
/* interpreter for special characters in name string */
char *name(char *buffer)
{
register char *ret;
char num[4] = "0x";
if (*buffer != '/')
return NULL;
ret = (char *) malloc(strlento(buffer, ' ') * sizeof(char));
while (*buffer != ' ') {
if (*buffer == '#') {
num[2] = *(buffer + 1);
num[3] = *(buffer + 2);
*ret = (char) strtoul((char *) &num, NULL, 16);
ret++;
buffer += 3;
}
*ret = *buffer;
ret++;
buffer++;
}
return ret;
}
/* parse arrays */
char **array(char *buffer)
{
register char **ret;
register int end, a, index;
if (*buffer != '[')
return NULL;
ret = (char **) malloc(strlenc(buffer, ' ', ']') * sizeof(char));
end = a = index = 0;
while (end > 0) {
switch (*buffer) {
case '[':
end++;
if (*(buffer + 1) == ' ') {
buffer += 2;
continue;
}
break;
case ']':
end--;
break;
case ' ':
if (*(buffer + 1) == ']')
break;
ret[index] = buffer - a;
*buffer = '\0';
a = 0;
index++;
break;
default:
a++;
}
buffer++;
}
return ret;
}
Platon Group <platon@platon.sk> http://platon.sk/
|