[project @ 2006-02-03 22:08:15 by unknown_lamer]
[clinton/bobotpp.git] / source / Parser.H
CommitLineData
cb21075d 1// Parser.H -*- C++ -*-
2// Copyright (c) 1997, 1998 Etienne BERNARD
4edefeb6 3// Copyright (c) 2002,2003 Clinton Ebadi
cb21075d 4
5// This program is free software; you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation; either version 2 of the License, or
8// any later version.
9
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
39b022cb 17// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
cb21075d 18
19#ifndef PARSER_H
20#define PARSER_H
21
22#ifdef HAVE_CONFIG_H
23#include "config.h"
24#endif
25
26#include "String.H"
27#include "Person.H"
28#include "ServerConnection.H"
29
30#ifdef USESCRIPTS
31#include "Interp.H"
32#include <libguile.h>
33#endif
34
439869bf 35#include <map>
36#include <string>
37
fed59248 38typedef void (*fptr)(ServerConnection *, Person *, String);
39
40// fptr is a parser function which may either be Scheme or C. fptr
41// used to be what funptr is now, but I decided to make the bot even
42// more extensible and it is now a function-like object that can be
43// used just like it was a function pointer.
44
45// This will take a lot of work to make it actually work...lots of
46// SMOBs have to be written :(
47
48// class fptr
49// {
50// private:
51// typedef void (*funptr)(ServerConnection *, Person *, String);
52// union
53// {
54// funptr Cfunc;
55// #ifdef USESCRIPTS
56// SCM Sfunc;
57// #endif
58// };
59// bool C;
60
61// public:
62// ftpr () { Cfunc = 0; Sfunc = 0; C = true; };
63// operator= (funptr f) { Cfunc = f; C = true; };
64// operator= (SCM f) { Sfunc = f; C = false; };
65
66// operator ()(ServerConnection * s, Person * p, String str)
67// {
68// if (C)
69// Cfunc (s, p, str);
70// else {}
71// // ... SCM not supported for now
72// }
e07b6b46 73// };
cb21075d 74
75class userFunction {
76public:
cb21075d 77 void (*function)(ServerConnection *, Person *, String, String);
78 int minLevel;
79 bool needsChannelName;
80#ifdef USESCRIPTS
81 int argsCount;
82 SCM scmFunc;
83#endif
84
e07b6b46 85 userFunction(void (*f)(ServerConnection *, Person *,
86 String, String) = 0,
87 int m = 0 , bool n = false
cb21075d 88#ifdef USESCRIPTS
89 , int a = -1, SCM scm_f = 0
90#endif
91 )
e07b6b46 92 : function(f), minLevel(m), needsChannelName(n)
cb21075d 93#ifdef USESCRIPTS
94 ,argsCount(a), scmFunc(scm_f)
95#endif
96 {
97#ifdef USESCRIPTS
e07b6b46 98 if (scmFunc)
99 scm_gc_protect_object(scmFunc);
cb21075d 100#endif
101 }
102
103#ifdef USESCRIPTS
e07b6b46 104 ~userFunction()
105 {
106 if (scmFunc)
107 scm_gc_unprotect_object(scmFunc);
108 }
cb21075d 109#endif
110};
111
112class Parser {
113public:
439869bf 114 static void init ();
cb21075d 115 static void parseLine(ServerConnection *, String);
116
117 static void parse001(ServerConnection *, Person *, String);
118 static void parse302(ServerConnection *, Person *, String);
119 static void parse311(ServerConnection *, Person *, String);
120 static void parse315(ServerConnection *, Person *, String);
121 static void parse324(ServerConnection *, Person *, String);
122 static void parse332(ServerConnection *, Person *, String);
123 static void parse352(ServerConnection *, Person *, String);
124 static void parse353(ServerConnection *, Person *, String);
125 static void parse366(ServerConnection *, Person *, String);
126 static void parse367(ServerConnection *, Person *, String);
127 static void parse401(ServerConnection *, Person *, String);
128 static void parse433(ServerConnection *, Person *, String);
129 static void parse473(ServerConnection *, Person *, String);
130 static void parseError(ServerConnection *, Person *, String);
131 static void parseInvite(ServerConnection *, Person *, String);
132 static void parseJoin(ServerConnection *, Person *, String);
133 static void parseKick(ServerConnection *, Person *, String);
134 static void parseMode(ServerConnection *, Person *, String);
135 static void parseNick(ServerConnection *, Person *, String);
136 static void parseNotice(ServerConnection *, Person *, String);
137 static void parsePart(ServerConnection *, Person *, String);
138 static void parsePing(ServerConnection *, Person *, String);
139 static void parsePong(ServerConnection *, Person *, String);
140 static void parsePrivmsg(ServerConnection *, Person *, String);
141 static void parseQuit(ServerConnection *, Person *, String);
142 static void parseTopic(ServerConnection *, Person *, String);
143
144 static void parseCTCP(ServerConnection *, Person *, String,
145 String);
146 static void parseMessage(ServerConnection *, Person *, String,
147 String);
148#ifdef USESCRIPTS
149 static void parseScriptFunction(ServerConnection *, String, bool,
150 SCM, int, String);
151#endif
152
153 static void sendNotice(Person *, String);
439869bf 154private:
155
439869bf 156 static std::map<std::string, fptr, std::less<std::string> > functions;
e07b6b46 157
cb21075d 158};
159
160#endif