File: cgi.ih

package info (click to toggle)
bobcat 3.01.00-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 6,612 kB
  • sloc: cpp: 12,107; makefile: 8,055; perl: 401; sh: 329
file content (127 lines) | stat: -rw-r--r-- 2,464 bytes parent folder | download
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
#include "cgi"

#include <vector>
#include <stack>
#include <cstring>
#include <istream>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <memory>

#include <sys/stat.h>
#include <sys/types.h>

#include <bobcat/a2x>
#include <bobcat/errno>
#include <bobcat/string>
#include <bobcat/x2a>
#include <bobcat/stat>
#include <bobcat/fswap>
#include <bobcat/ranger>

using namespace std;
using namespace FBB;

namespace FBB
{

typedef pair<char const *const, int (*const)(int)> PairCPPFunP;

class CGIFSA
{
    enum Token
    {
        DEFAULT = 256,
        SET,
        END,
    };            
    enum State         // change data.cc s_stateName when this changes
    {   
        START,
        CHECKSET,
        DEFINESET,
        OPENBRACKET,
        LEFTCOLON,
        SETNAME,
        RIGHTCOLON,

        N_STATES_,
        STOP = N_STATES_,
    };

    struct Record
    {
        State   current;
        size_t  token;
        void    (CGIFSA::*action)();
        State   next;
        size_t  (CGIFSA::*tokenizer)();
    };

    stack<char> d_stack;
    bool *d_escape;
    bool d_setEscape;
    State d_state;
    size_t  d_tokenIdx;
    string d_buffer;
    size_t  d_setIdx;
    istream &d_in;
           
    struct Transition
    {
        size_t  token;
        void (CGIFSA::*action)();
        State   next;
    };

    static vector<Transition> s_fsa[];
    static size_t (CGIFSA::*s_tokenizer[])();
    static Record const s_fsaRawData[];
    static Record const *const s_fsaRawDataEnd;
    static PairCPPFunP const s_charClass[];
    static PairCPPFunP const *const s_charClassEnd;
    static bool s_installed;
    static char const *s_stateName[];
    static string s_cgi;

    public:
        CGIFSA(bool *escape, istream &in = cin, bool setEscape = false);
        void run();

    private:
        void push();
        void accept();
        void charRange();
        void charClass();

        void acceptAll();           // all elements on the stack

        size_t tokenIdx();

        void setEscape(size_t idx);
    
        size_t charToken();
        size_t wordToken();

        static void setFsa(Record const &record);
        static int iscgi(int ch);
};

inline int CGIFSA::iscgi(int ch)
{
    return s_cgi.find(ch) != string::npos;
}

inline void CGIFSA::setEscape(size_t idx)
{
    d_escape[idx] = d_setEscape;
}

//inline void CGI::init(bool &target)
//{
//    target = d_escapeValue;
//}


}   // namespace