comparison irccd-test/main.cpp @ 657:c09aee75fde4

Irccd: style (irccd-test) #782 While here, fix infinite loop in case of ^D in non-libedit builds.
author David Demelier <markand@malikania.fr>
date Tue, 27 Mar 2018 21:10:00 +0200
parents aae6d5a2b28d
children c0c2926a35df
comparison
equal deleted inserted replaced
656:2838134d69bf 657:c09aee75fde4
91 /* 91 /*
92 * onCommand server origin channel message 92 * onCommand server origin channel message
93 */ 93 */
94 void on_command(const std::string& data) 94 void on_command(const std::string& data)
95 { 95 {
96 auto args = su::split(data, " ", 4); 96 const auto args = su::split(data, " ", 4);
97 97
98 plugin->handle_command(*daemon, { 98 plugin->handle_command(*daemon, {
99 get_server(get_arg(args, 0)), 99 get_server(get_arg(args, 0)),
100 get_arg(args, 1), 100 get_arg(args, 1),
101 get_arg(args, 2), 101 get_arg(args, 2),
106 /* 106 /*
107 * onConnect server 107 * onConnect server
108 */ 108 */
109 void on_connect(const std::string& data) 109 void on_connect(const std::string& data)
110 { 110 {
111 const auto args = su::split(data, " ");
112
113 plugin->handle_connect(*daemon, {get_server(get_arg(args, 0))});
114 }
115
116 /*
117 * onInvite server origin channel target
118 */
119 void on_invite(const std::string& data)
120 {
111 auto args = su::split(data, " "); 121 auto args = su::split(data, " ");
112 122
113 plugin->handle_connect(*daemon, {get_server(get_arg(args, 0))});
114 }
115
116 /*
117 * onInvite server origin channel target
118 */
119 void on_invite(const std::string& data)
120 {
121 auto args = su::split(data, " ");
122
123 plugin->handle_invite(*daemon, { 123 plugin->handle_invite(*daemon, {
124 get_server(get_arg(args, 0)), 124 get_server(get_arg(args, 0)),
125 get_arg(args, 1), 125 get_arg(args, 1),
126 get_arg(args, 2), 126 get_arg(args, 2),
127 get_arg(args, 3), 127 get_arg(args, 3),
131 /* 131 /*
132 * onJoin server origin channel 132 * onJoin server origin channel
133 */ 133 */
134 void on_join(const std::string& data) 134 void on_join(const std::string& data)
135 { 135 {
136 auto args = su::split(data, " "); 136 const auto args = su::split(data, " ");
137 137
138 plugin->handle_join(*daemon, { 138 plugin->handle_join(*daemon, {
139 get_server(get_arg(args, 0)), 139 get_server(get_arg(args, 0)),
140 get_arg(args, 1), 140 get_arg(args, 1),
141 get_arg(args, 2) 141 get_arg(args, 2)
145 /* 145 /*
146 * onKick server origin channel reason 146 * onKick server origin channel reason
147 */ 147 */
148 void on_kick(const std::string& data) 148 void on_kick(const std::string& data)
149 { 149 {
150 auto args = su::split(data, " ", 5); 150 const auto args = su::split(data, " ", 5);
151 151
152 plugin->handle_kick(*daemon, { 152 plugin->handle_kick(*daemon, {
153 get_server(get_arg(args, 0)), 153 get_server(get_arg(args, 0)),
154 get_arg(args, 1), 154 get_arg(args, 1),
155 get_arg(args, 2), 155 get_arg(args, 2),
169 /* 169 /*
170 * onMe server origin channel message 170 * onMe server origin channel message
171 */ 171 */
172 void on_me(const std::string& data) 172 void on_me(const std::string& data)
173 { 173 {
174 auto args = su::split(data, " ", 4); 174 const auto args = su::split(data, " ", 4);
175 175
176 plugin->handle_me(*daemon, { 176 plugin->handle_me(*daemon, {
177 get_server(get_arg(args, 0)), 177 get_server(get_arg(args, 0)),
178 get_arg(args, 1), 178 get_arg(args, 1),
179 get_arg(args, 2), 179 get_arg(args, 2),
184 /* 184 /*
185 * onMessage server origin channel message 185 * onMessage server origin channel message
186 */ 186 */
187 void on_message(const std::string& data) 187 void on_message(const std::string& data)
188 { 188 {
189 auto args = su::split(data, " ", 4); 189 const auto args = su::split(data, " ", 4);
190 190
191 plugin->handle_message(*daemon, { 191 plugin->handle_message(*daemon, {
192 get_server(get_arg(args, 0)), 192 get_server(get_arg(args, 0)),
193 get_arg(args, 1), 193 get_arg(args, 1),
194 get_arg(args, 2), 194 get_arg(args, 2),
199 /* 199 /*
200 * onMode server origin channel mode limit user mask 200 * onMode server origin channel mode limit user mask
201 */ 201 */
202 void on_mode(const std::string& data) 202 void on_mode(const std::string& data)
203 { 203 {
204 auto args = su::split(data, " ", 7); 204 const auto args = su::split(data, " ", 7);
205 205
206 plugin->handle_mode(*daemon, { 206 plugin->handle_mode(*daemon, {
207 get_server(get_arg(args, 0)), 207 get_server(get_arg(args, 0)),
208 get_arg(args, 1), 208 get_arg(args, 1),
209 get_arg(args, 2), 209 get_arg(args, 2),
217 /* 217 /*
218 * onNames server channel nick1 nick2 nickN 218 * onNames server channel nick1 nick2 nickN
219 */ 219 */
220 void on_names(const std::string& data) 220 void on_names(const std::string& data)
221 { 221 {
222 auto args = su::split(data, " "); 222 const auto args = su::split(data, " ");
223 223
224 names_event ev; 224 names_event ev;
225 225
226 ev.server = get_server(get_arg(args, 0)); 226 ev.server = get_server(get_arg(args, 0));
227 ev.channel = get_arg(args, 1); 227 ev.channel = get_arg(args, 1);
235 /* 235 /*
236 * onNick server origin nickname 236 * onNick server origin nickname
237 */ 237 */
238 void on_nick(const std::string& data) 238 void on_nick(const std::string& data)
239 { 239 {
240 auto args = su::split(data, " "); 240 const auto args = su::split(data, " ");
241 241
242 plugin->handle_nick(*daemon, { 242 plugin->handle_nick(*daemon, {
243 get_server(get_arg(args, 0)), 243 get_server(get_arg(args, 0)),
244 get_arg(args, 1), 244 get_arg(args, 1),
245 get_arg(args, 2) 245 get_arg(args, 2)
249 /* 249 /*
250 * onNotice server origin channel nickname 250 * onNotice server origin channel nickname
251 */ 251 */
252 void on_notice(const std::string& data) 252 void on_notice(const std::string& data)
253 { 253 {
254 auto args = su::split(data, " ", 4); 254 const auto args = su::split(data, " ", 4);
255 255
256 plugin->handle_notice(*daemon, { 256 plugin->handle_notice(*daemon, {
257 get_server(get_arg(args, 0)), 257 get_server(get_arg(args, 0)),
258 get_arg(args, 1), 258 get_arg(args, 1),
259 get_arg(args, 2), 259 get_arg(args, 2),
264 /* 264 /*
265 * onPart server origin channel reason 265 * onPart server origin channel reason
266 */ 266 */
267 void on_part(const std::string& data) 267 void on_part(const std::string& data)
268 { 268 {
269 auto args = su::split(data, " ", 4); 269 const auto args = su::split(data, " ", 4);
270 270
271 plugin->handle_part(*daemon, { 271 plugin->handle_part(*daemon, {
272 get_server(get_arg(args, 0)), 272 get_server(get_arg(args, 0)),
273 get_arg(args, 1), 273 get_arg(args, 1),
274 get_arg(args, 2), 274 get_arg(args, 2),
287 /* 287 /*
288 * onTopic server origin channel topic 288 * onTopic server origin channel topic
289 */ 289 */
290 void on_topic(const std::string& data) 290 void on_topic(const std::string& data)
291 { 291 {
292 auto args = su::split(data, " ", 4); 292 const auto args = su::split(data, " ", 4);
293 293
294 plugin->handle_topic(*daemon, { 294 plugin->handle_topic(*daemon, {
295 get_server(get_arg(args, 0)), 295 get_server(get_arg(args, 0)),
296 get_arg(args, 1), 296 get_arg(args, 1),
297 get_arg(args, 2), 297 get_arg(args, 2),
310 /* 310 /*
311 * onWhois server nick user host realname chan1 chan2 chanN 311 * onWhois server nick user host realname chan1 chan2 chanN
312 */ 312 */
313 void on_whois(const std::string& data) 313 void on_whois(const std::string& data)
314 { 314 {
315 auto args = su::split(data, " "); 315 const auto args = su::split(data, " ");
316 316
317 whois_event ev; 317 whois_event ev;
318 318
319 ev.server = get_server(get_arg(args, 0)); 319 ev.server = get_server(get_arg(args, 0));
320 ev.whois.nick = get_arg(args, 1); 320 ev.whois.nick = get_arg(args, 1);
354 { "onWhois", &(on_whois) } 354 { "onWhois", &(on_whois) }
355 }; 355 };
356 356
357 void exec(const std::string& line) 357 void exec(const std::string& line)
358 { 358 {
359 auto pos = line.find(' '); 359 const auto pos = line.find(' ');
360 auto it = list.find(line.substr(0, pos)); 360 const auto it = list.find(line.substr(0, pos));
361 361
362 if (it != list.end()) 362 if (it != list.end())
363 it->second(pos == std::string::npos ? "" : line.substr(pos + 1)); 363 it->second(pos == std::string::npos ? "" : line.substr(pos + 1));
364 } 364 }
365 365
447 { 447 {
448 std::string line; 448 std::string line;
449 449
450 for (;;) { 450 for (;;) {
451 std::cout << "> "; 451 std::cout << "> ";
452 std::getline(std::cin, line); 452
453 if (!std::getline(std::cin, line))
454 return;
455
453 exec(line); 456 exec(line);
454 } 457 }
455 } 458 }
456 459
457 #endif 460 #endif