-
Notifications
You must be signed in to change notification settings - Fork 16
/
parser.h
86 lines (78 loc) · 2.05 KB
/
parser.h
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
/** vim: set ts=4 sw=4 et tw=99:
*
* === Stripper for Metamod:Source ===
* Copyright (C) 2005-2009 David "BAILOPAN" Anderson
* No warranties of any kind.
* Based on the original concept of Stripper2 by botman
*
* License: see LICENSE.TXT
* ===================================
*/
#ifndef _INCLUDE_STRIP_PARSER_H
#define _INCLUDE_STRIP_PARSER_H
#include <sh_string.h>
#include <sh_list.h>
#include <sh_stack.h>
#include "pcre.h"
struct CACHEABLE
{
#if defined _DEBUG
CACHEABLE() : marked(true), last_alloc(0), last_free(0) { };
bool marked;
int last_alloc;
int last_free;
#endif
};
struct parse_pair
{
SourceHook::String key;
SourceHook::String val;
pcre *re;
};
struct ent_prop : public CACHEABLE
{
SourceHook::String key;
SourceHook::String val;
};
struct replace_prop
{
SourceHook::List<parse_pair *> match;
SourceHook::List<parse_pair *> to_replace;
SourceHook::List<parse_pair *> to_remove;
SourceHook::List<parse_pair *> to_insert;
};
class Stripper
{
public:
Stripper();
~Stripper();
public:
void SetEntityList(const char *ents);
void ApplyFileFilter(const char *file);
const char *ToString();
private:
void RunRemoveFilter(SourceHook::List<parse_pair *> &filters);
void RunAddFilter(SourceHook::List<parse_pair *> &list);
void RunReplaceFilter(replace_prop &replace, SourceHook::List<parse_pair *> &props);
void Clear();
void _BuildPropList();
private:
SourceHook::String *AllocString();
void FreeString(SourceHook::String *str);
ent_prop *AllocProp();
void FreeProp(ent_prop *prop);
private:
SourceHook::CStack<SourceHook::String *> m_StringCache;
SourceHook::CStack<ent_prop *> m_PropCache;
void AppendToString(const char* buf, size_t len);
private:
char* m_tostring;
size_t m_tostring_len;
size_t m_tostring_maxlen;
SourceHook::List<SourceHook::List<ent_prop *> *> m_props;
SourceHook::List<SourceHook::String *> m_lines;
bool m_resync;
pcre *brk_re;
pcre_extra *brk_re_extra;
};
#endif /* _INCLUDE_STRIP_PARSER_H */