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
|
/*
GameSpy GT2 SDK
GT2Action - sample app
Dan "Mr. Pants" Schoenblum
dan@gamespy.com
Copyright 2000 GameSpy Industries, Inc
*/
#include <string.h>
#include "gt2aParse.h"
static char buffer[256];
static char * StripKeyValue
(
char * input
)
{
int i;
int c;
// Get the key.
///////////////
for(i = 0 ; i < (sizeof(buffer) - 1) ; i++)
{
c = *input++;
if((c == '\\') || (c == '\0'))
break;
buffer[i] = (char)c;
}
buffer[i] = '\0';
return buffer;
}
char * ParseKeyValue
(
char * input,
const char * key
)
{
char * str;
int len;
if(!input)
return NULL;
// Are we looking for the first key?
////////////////////////////////////
if(!key)
{
// Does it start with a '\'?
////////////////////////////
if(*input++ != '\\')
return NULL;
// Get the key.
///////////////
return StripKeyValue(input);
}
// Find the key.
////////////////
buffer[0] = '\\';
len = strlen(key);
memcpy(buffer + 1, key, len);
buffer[++len] = '\\';
buffer[++len] = '\0';
str = strstr(input, buffer);
if(!str)
return NULL;
str += strlen(buffer);
// Get the key.
///////////////
return StripKeyValue(str);
}
|