File: gt2aParse.c

package info (click to toggle)
openmohaa 0.82.1%2Bdfsg-1
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 34,192 kB
  • sloc: cpp: 315,720; ansic: 275,789; sh: 312; xml: 246; asm: 141; makefile: 7
file content (79 lines) | stat: -rw-r--r-- 1,140 bytes parent folder | download | duplicates (2)
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);
}