forked from JACoders/OpenJK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.cpp
144 lines (123 loc) · 2.58 KB
/
parser.cpp
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Filename:- parser.cpp
//
#include "stdafx.h"
#include "includes.h"
#include "stl.h"
//
#include "parser.h"
// Very simple parser, I just read the "alias" part of a raven-generic file, and store them into
// a string map.
//
// Example file:
//
/*
Alias
{
"srcarples" "boltpoint_righthand"
}
Alias
{
"slcarples" "boltpoint_lefthand"
}
*/
// (possibly more than one per "Alias" brace? I'll code for it.
//
// return = success / fail...
//
bool Parser_Load(LPCSTR psFullPathedFilename, MappedString_t &ParsedAliases)
{
bool bReturn = false;
ParsedAliases.clear();
FILE *fhHandle = fopen(psFullPathedFilename,"rt");
if (fhHandle)
{
bool bParsingBlock = false;
bool bSkippingBlock= false;
char sLine[1024];
while (fgets(sLine,sizeof(sLine)-1,fhHandle)!=NULL)
{
sLine[sizeof(sLine)-1]='\0';
// :-)
CString str(sLine);
str.TrimLeft();
str.TrimRight();
strcpy(sLine,str);
if (!bSkippingBlock)
{
if (!bParsingBlock)
{
if (strlen(sLine)) // found any kind of header?
{
if (!stricmp(sLine,"Alias"))
{
bParsingBlock = true;
}
else
{
// not a recognised header, so...
//
bSkippingBlock = true;
}
}
continue;
}
else
{
if (!stricmp(sLine,"{"))
continue;
if (!stricmp(sLine,"}"))
{
bParsingBlock = false;
continue;
}
if (strlen(sLine))
{
// must be a value pair, so...
//
// first, find the whitespace that seperates them...
//
CString strPair(sLine);
int iLoc = strPair.FindOneOf(" \t");
if (iLoc == -1)
{
assert(0);
ErrorBox(va("Parser_Load(): Couldn't find whitespace-seperator in line:\n\n\"%s\"\n\n( File: \"%s\" )",(LPCSTR) strPair,psFullPathedFilename));
bReturn = false;
break;
}
// stl & MFC rule!...
//
CString strArg_Left(strPair.Left(iLoc)); // real name
strArg_Left.TrimRight();
strArg_Left.Replace("\"","");
CString strArg_Right(strPair.Mid (iLoc)); // alias name
strArg_Right.TrimLeft();
strArg_Right.Replace("\"","");
ParsedAliases[(LPCSTR)strArg_Left] = (LPCSTR)strArg_Right;
bReturn = true;
continue;
}
}
}
else
{
// skip to close brace...
//
if (stricmp(sLine,"}"))
continue;
bSkippingBlock = false;
}
}
fclose(fhHandle);
}
// DT EDIT
/*
else
{
ErrorBox( va("Couldn't open file: %s\n", psFullPathedFilename));
return false;
}
*/
return bReturn;
}
/////////////// eof /////////////