parser.h
author Dr!fter <drifter01620@gmail.com>
Sat Aug 16 22:29:47 2014 -0400 (2014-08-16)
changeset 79 c782ba2e5b1b
parent 21 3c10031b140d
permissions -rw-r--r--
Set temporary enviroment variables.
     1 /** vim: set ts=4 sw=4 et tw=99:
     2  * 
     3  * === Stripper for Metamod:Source ===
     4  * Copyright (C) 2005-2009 David "BAILOPAN" Anderson
     5  * No warranties of any kind.
     6  * Based on the original concept of Stripper2 by botman
     7  *
     8  * License: see LICENSE.TXT
     9  * ===================================
    10  */
    11 #ifndef _INCLUDE_STRIP_PARSER_H
    12 #define _INCLUDE_STRIP_PARSER_H
    13 
    14 #include <sh_string.h>
    15 #include <sh_list.h>
    16 #include <sh_stack.h>
    17 #include "pcre.h"
    18 
    19 struct CACHEABLE
    20 {
    21 #if defined _DEBUG
    22     CACHEABLE() : marked(true), last_alloc(0), last_free(0) { };
    23     bool marked;
    24     int last_alloc;
    25     int last_free;
    26 #endif
    27 };
    28 
    29 struct parse_pair
    30 {
    31     SourceHook::String key;
    32     SourceHook::String val;
    33     pcre *re;
    34 };
    35 
    36 struct ent_prop : public CACHEABLE
    37 {
    38     SourceHook::String key;
    39     SourceHook::String val;
    40 };
    41 
    42 struct replace_prop
    43 {
    44     SourceHook::List<parse_pair *> match;
    45     SourceHook::List<parse_pair *> to_replace;
    46     SourceHook::List<parse_pair *> to_remove;
    47     SourceHook::List<parse_pair *> to_insert;
    48 };
    49 
    50 class Stripper
    51 {
    52 public:
    53     Stripper();
    54     ~Stripper();
    55 public:
    56     void SetEntityList(const char *ents);
    57     void ApplyFileFilter(const char *file);
    58     const char *ToString();
    59 private:
    60     void RunRemoveFilter(SourceHook::List<parse_pair *> &filters);
    61     void RunAddFilter(SourceHook::List<parse_pair *> &list);
    62     void RunReplaceFilter(replace_prop &replace, SourceHook::List<parse_pair *> &props);
    63     void Clear();
    64     void _BuildPropList();
    65 private:
    66     SourceHook::String *AllocString();
    67     void FreeString(SourceHook::String *str);
    68     ent_prop *AllocProp();
    69     void FreeProp(ent_prop *prop);
    70 private:
    71     SourceHook::CStack<SourceHook::String *> m_StringCache;
    72     SourceHook::CStack<ent_prop *> m_PropCache;
    73     void AppendToString(const char* buf, size_t len);
    74 private:
    75     char* m_tostring;
    76     size_t m_tostring_len;
    77     size_t m_tostring_maxlen;
    78     SourceHook::List<SourceHook::List<ent_prop *> *> m_props;
    79     SourceHook::List<SourceHook::String *> m_lines;
    80     bool m_resync;
    81     pcre *brk_re;
    82     pcre_extra *brk_re_extra;
    83 };
    84 
    85 #endif /* _INCLUDE_STRIP_PARSER_H */
    86