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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
#ifndef CHAN_PARSER_H
#define CHAN_PARSER_H
#include <qcolor.h>
#include <qdict.h>
/*
* This file defines the parser, and all exceptions generated
* by the toplevel parse_input function.
*/
class ChannelParser; // Main class defined
class QString;
class KSircTopLevel;
class parseResult
{
public:
parseResult() { }
virtual ~parseResult() { }
// Empty
};
/*
* Parsing is ok, this is the string to display
*/
class parseSucc : public parseResult
{
public:
QString string; // String to display
QColor colour;
QString pm;
parseSucc(const QString &_s, const QColor &_c = QColor(), const QString &_pm = QString::null){
string = _s;
colour = _c;
pm = _pm;
}
};
/*
* parseError is a fatal error message.
* arg0: if it is not empty, it will get displayed to the channel screen (in error colour with mad smile)
* arg1: if none empty goes to stderr
*/
class parseError : public parseResult
{
public:
QString str;
QString err;
parseError(const QString &_s, const QString &_e)
{
str = _s;
err = _e;
}
};
class parseWrongChannel : public parseSucc
{
public:
parseWrongChannel(const QString &_s, const QColor &_c = QColor(), const QString &_pm = QString::null)
: parseSucc(_s, _c, _pm)
{
}
};
class parseJoinPart : public parseSucc
{
public:
parseJoinPart(const QString &_s, const QColor &_c = QColor(), const QString &_pm = QString::null)
: parseSucc(_s, _c, _pm)
{
}
};
class infoFoundNick {
public:
char nick[101];
infoFoundNick(char *_n){
strncpy(nick, _n, 100);
nick[100]='\0';
}
};
class badModeChangeError // Mode change barfed up, exit out
{
public:
QString str;
char *msg;
badModeChangeError(QString _str, char *_msg)
{
str = _str;
msg = _msg;
}
};
class wrongChannelError // Message was not intended for us, display str and continue
{
public:
int display;
wrongChannelError(int _display)
{
display = _display;
}
};
class doneModes // Finished parsing modes from the extModes string
{
public:
doneModes(int /*i*/)
{
}
};
// End of exceptions
class parseFunc
{
public:
parseResult *(ChannelParser::*parser)(QString);
parseFunc(parseResult *(ChannelParser::*_parser)(QString)){
parser = _parser;
}
private:
parseFunc(); // Disable the default no argument constructor
};
class ChannelParser {
public:
/**
* ChannelParser takes a KSircTopLevel as it's first argument so
* we can refrence it latter.
*
* NOTE: the KSircTopLevel befriends the parser so we can have access to.
* NOTE2: don't abuse this you little wanker.
*/
ChannelParser(KSircTopLevel *_top);
/**
* parse() thanks the string to be parsed and parses it.
* It returns a class of type 'parseResult' or 0.
*/
parseResult *parse(QString string);
private:
KSircTopLevel *top;
/**
* These are helper variables used internally in the parsing functions
*/
bool prompt_active;
int current_item;
int top_item;
/**
* The parser Table holds a list of functions with parse
* sepecific commands and arguments. The key for the dict is the
* first 3 characters of the "search key" for the string type.
*
* Even through the parserTable is static, the functions called manipulate
* this object.
*
* The functions do the following:
* - On succesfull compleion: generte a parseSucc exception
* - On failure generate: parseFailed, etc
*/
static QDict<parseFunc> parserTable;
/*
* Note regarding ssfe control messages:
*
* They are converted from the form `#ssfe#<COMMAND> to `<COMMAND>`
* t/m is converted to t
*/
/**
* Start of the praser function definitions
*
* Each function returns void (since they never return it does matter)
* 1 argument, the string to parse
*
*/
/**
* SSFE clear 'l' function, clears main window
*/
parseResult * parseSSFEClear(QString string);
/**
* SSFE Status is used to update caption, and op status
*
*/
parseResult * parseSSFEStatus(QString string);
/**
* SSFE Init is called by ssfe when it's time to init and setup
*/
parseResult * parseSSFEInit(QString string);
/**
* SSFE msg is called for each /msg sent to a diffrent user
*/
parseResult * parseSSFEMsg(QString string);
/**
* SSFE Out, not used
*/
parseResult * parseSSFEOut(QString string);
/**
* SSFE Prompt, same function used for p and P, gives a password prompt
*/
parseResult * parseSSFEPrompt(QString string);
/**
* SSFE Reconnect called when (re)connected to a server
*/
parseResult * parseSSFEReconnect(QString string);
/**
* That's all the SSFE control messages, the rest are info *\S* message
*/
/**
* *** is a generic infomation messge
*/
parseResult * parseINFOInfo(QString string);
/**
* *E* is a error message
*/
parseResult * parseINFOError(QString string);
/**
* *#* is a list of nicks, used to update the nick list if it's for
* the current channel.
*/
parseResult * parseINFONicks(QString in_string);
/**
* *>* is a join message. If it's for the current channel
*/
parseResult * parseINFOJoin(QString string);
/**
* *<* is a part message, if it's for the current channel remove it.
* There's multiple part types, so parsing it more complicated.
*/
parseResult * parseINFOPart(QString string);
/**
* *N* Is a nick change, update the nick list if needed
* Nick changes go outto all windows, so the nick may not be on
* out current channel.
*/
parseResult * parseINFOChangeNick(QString string);
/*
* *M* is a mode change. Parsing is mode changes is probably the most
* complicated of all the parsings
*/
parseResult * parseINFOMode(QString string);
/*
* * is a ctcp actiion. Simply print a pretty * for the user
*/
parseResult * parseCTCPAction(QString string);
/*
* *T* is a topic message, catch it and update the status is required
*/
parseResult * parseINFOTopic(QString string);
private:
void highlightNick(QString &string, QString &nick);
};
#endif
|