kike: generate replies from a single text file
It became a bit difficult to maintain two separate lists. Besides, the inverse generation of a message catalog from source code was a bit strange.
This commit is contained in:
parent
bd68e28b60
commit
126c07b70a
|
@ -2,6 +2,7 @@
|
|||
/zyklonb
|
||||
/kike
|
||||
/kike.msg
|
||||
/kike-replies.c
|
||||
|
||||
# Qt Creator files
|
||||
/ZyklonB.*
|
||||
|
|
15
Makefile
15
Makefile
|
@ -8,19 +8,20 @@ CFLAGS = -std=c99 -Wall -Wextra -Wno-unused-function \
|
|||
LDFLAGS = `pkg-config --libs libssl` -lpthread
|
||||
|
||||
.PHONY: all clean
|
||||
.SUFFIXES:
|
||||
|
||||
targets = zyklonb kike kike.msg
|
||||
|
||||
all: $(targets)
|
||||
|
||||
clean:
|
||||
rm -f $(targets)
|
||||
rm -f $(targets) kike-replies.c
|
||||
|
||||
zyklonb: src/zyklonb.c src/common.c src/siphash.c
|
||||
$(CC) src/zyklonb.c src/siphash.c -o $@ $(CFLAGS) $(LDFLAGS)
|
||||
zyklonb: zyklonb.c common.c siphash.c
|
||||
$(CC) zyklonb.c siphash.c -o $@ $(CFLAGS) $(LDFLAGS)
|
||||
kike: kike.c common.c siphash.c kike-replies.c
|
||||
$(CC) kike.c siphash.c -o $@ $(CFLAGS) $(LDFLAGS)
|
||||
|
||||
kike: src/kike.c src/common.c src/siphash.c
|
||||
$(CC) src/kike.c src/siphash.c -o $@ $(CFLAGS) $(LDFLAGS)
|
||||
kike.msg: src/kike.c
|
||||
$(SHELL) kike-extract-messages.sh < $< > $@
|
||||
kike-replies.c kike.msg: kike-replies
|
||||
$(SHELL) kike-gen-replies.sh < $< > $@
|
||||
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
#!/bin/sh
|
||||
LC_ALL=C exec awk '
|
||||
BEGIN {
|
||||
print "$quote \"";
|
||||
print "$set 1";
|
||||
}
|
||||
/^\tIRC_(ERR|RPL)_[A-Z]+ *= *[0-9]+,?$/ {
|
||||
match($3, /^[0-9]+/);
|
||||
id[$1] = substr($3, RSTART, RLENGTH);
|
||||
}
|
||||
/^\t\[IRC_(ERR|RPL)_[A-Z]+\] *= *".*",?$/ {
|
||||
z = substr($1, 2, length($1) - 2);
|
||||
match($0, /".*"/);
|
||||
print id[z] " " substr($0, RSTART, RLENGTH);
|
||||
}'
|
|
@ -0,0 +1,28 @@
|
|||
#!/bin/sh
|
||||
LC_ALL=C exec awk '
|
||||
BEGIN {
|
||||
# The message catalog is a byproduct
|
||||
msg = "kike.msg"
|
||||
print "$quote \"" > msg;
|
||||
print "$set 1" > msg;
|
||||
}
|
||||
/^[0-9]+ *IRC_(ERR|RPL)_[A-Z]+ *".*"$/ {
|
||||
match($0, /".*"/);
|
||||
ids[$1] = $2;
|
||||
texts[$2] = substr($0, RSTART, RLENGTH);
|
||||
print $1 " " texts[$2] > msg
|
||||
}
|
||||
END {
|
||||
printf("enum\n{")
|
||||
for (i in ids) {
|
||||
if (seen_first)
|
||||
printf(",")
|
||||
seen_first = 1
|
||||
printf("\n\t%s = %s", ids[i], i)
|
||||
}
|
||||
print "\n};\n"
|
||||
print "static const char *g_default_replies[] =\n{"
|
||||
for (i in ids)
|
||||
print "\t[" ids[i] "] = " texts[ids[i]] ","
|
||||
print "};"
|
||||
}'
|
|
@ -0,0 +1,72 @@
|
|||
1 IRC_RPL_WELCOME ":Welcome to the Internet Relay Network %s!%s@%s"
|
||||
2 IRC_RPL_YOURHOST ":Your host is %s, running version %s"
|
||||
3 IRC_RPL_CREATED ":This server was created %s"
|
||||
4 IRC_RPL_MYINFO "%s %s %s %s"
|
||||
221 IRC_RPL_UMODEIS "+%s"
|
||||
251 IRC_RPL_LUSERCLIENT ":There are %d users and %d services on %d servers"
|
||||
252 IRC_RPL_LUSEROP "%d :operator(s) online"
|
||||
253 IRC_RPL_LUSERUNKNOWN "%d :unknown connection(s)"
|
||||
254 IRC_RPL_LUSERCHANNELS "%d :channels formed"
|
||||
255 IRC_RPL_LUSERME ":I have %d clients and %d servers"
|
||||
301 IRC_RPL_AWAY "%s :%s"
|
||||
302 IRC_RPL_USERHOST ":%s"
|
||||
303 IRC_RPL_ISON ":%s"
|
||||
305 IRC_RPL_UNAWAY ":You are no longer marked as being away"
|
||||
306 IRC_RPL_NOWAWAY ":You have been marked as being away"
|
||||
311 IRC_RPL_WHOISUSER "%s %s %s * :%s"
|
||||
312 IRC_RPL_WHOISSERVER "%s %s :%s"
|
||||
313 IRC_RPL_WHOISOPERATOR "%s :is an IRC operator"
|
||||
315 IRC_RPL_ENDOFWHO "%s :End of WHO list"
|
||||
317 IRC_RPL_WHOISIDLE "%s %d :seconds idle"
|
||||
318 IRC_RPL_ENDOFWHOIS "%s :End of WHOIS list"
|
||||
319 IRC_RPL_WHOISCHANNELS "%s :%s"
|
||||
322 IRC_RPL_LIST "%s %d :%s"
|
||||
323 IRC_RPL_LISTEND ":End of LIST"
|
||||
324 IRC_RPL_CHANNELMODEIS "%s +%s"
|
||||
331 IRC_RPL_NOTOPIC "%s :No topic is set"
|
||||
332 IRC_RPL_TOPIC "%s :%s"
|
||||
346 IRC_RPL_INVITELIST "%s %s"
|
||||
347 IRC_RPL_ENDOFINVITELIST "%s :End of channel invite list"
|
||||
348 IRC_RPL_EXCEPTLIST "%s %s"
|
||||
349 IRC_RPL_ENDOFEXCEPTLIST "%s :End of channel exception list"
|
||||
351 IRC_RPL_VERSION "%s.%d %s :%s"
|
||||
352 IRC_RPL_WHOREPLY "%s %s %s %s %s %s :%d %s"
|
||||
353 IRC_RPL_NAMREPLY "%c %s :%s"
|
||||
366 IRC_RPL_ENDOFNAMES "%s :End of NAMES list"
|
||||
367 IRC_RPL_BANLIST "%s %s"
|
||||
368 IRC_RPL_ENDOFBANLIST "%s :End of channel ban list"
|
||||
372 IRC_RPL_MOTD ":- %s"
|
||||
375 IRC_RPL_MOTDSTART ":- %s Message of the day - "
|
||||
376 IRC_RPL_ENDOFMOTD ":End of MOTD command"
|
||||
391 IRC_RPL_TIME "%s :%s"
|
||||
401 IRC_ERR_NOSUCHNICK "%s :No such nick/channel"
|
||||
402 IRC_ERR_NOSUCHSERVER "%s :No such server"
|
||||
403 IRC_ERR_NOSUCHCHANNEL "%s :No such channel"
|
||||
404 IRC_ERR_CANNOTSENDTOCHAN "%s :Cannot send to channel"
|
||||
409 IRC_ERR_NOORIGIN ":No origin specified"
|
||||
411 IRC_ERR_NORECIPIENT ":No recipient given (%s)"
|
||||
412 IRC_ERR_NOTEXTTOSEND ":No text to send"
|
||||
421 IRC_ERR_UNKNOWNCOMMAND "%s: Unknown command"
|
||||
422 IRC_ERR_NOMOTD ":MOTD File is missing"
|
||||
423 IRC_ERR_NOADMININFO "%s :No administrative info available"
|
||||
431 IRC_ERR_NONICKNAMEGIVEN ":No nickname given"
|
||||
432 IRC_ERR_ERRONEOUSNICKNAME "%s :Erroneous nickname"
|
||||
433 IRC_ERR_NICKNAMEINUSE "%s :Nickname is already in use"
|
||||
441 IRC_ERR_USERNOTINCHANNEL "%s %s :They aren't on that channel"
|
||||
442 IRC_ERR_NOTONCHANNEL "%s :You're not on that channel"
|
||||
445 IRC_ERR_SUMMONDISABLED ":SUMMON has been disabled"
|
||||
446 IRC_ERR_USERSDISABLED ":USERS has been disabled"
|
||||
451 IRC_ERR_NOTREGISTERED ":You have not registered"
|
||||
461 IRC_ERR_NEEDMOREPARAMS "%s :Not enough parameters"
|
||||
462 IRC_ERR_ALREADYREGISTERED ":Unauthorized command (already registered)"
|
||||
467 IRC_ERR_KEYSET "%s :Channel key already set"
|
||||
471 IRC_ERR_CHANNELISFULL "%s :Cannot join channel (+l)"
|
||||
472 IRC_ERR_UNKNOWNMODE "%c :is unknown mode char to me for %s"
|
||||
473 IRC_ERR_INVITEONLYCHAN "%s :Cannot join channel (+i)"
|
||||
474 IRC_ERR_BANNEDFROMCHAN "%s :Cannot join channel (+b)"
|
||||
475 IRC_ERR_BADCHANNELKEY "%s :Cannot join channel (+k)"
|
||||
476 IRC_ERR_BADCHANMASK "%s :Bad Channel Mask"
|
||||
481 IRC_ERR_NOPRIVILEGES ":Permission Denied- You're not an IRC operator"
|
||||
482 IRC_ERR_CHANOPRIVSNEEDED "%s :You're not channel operator"
|
||||
501 IRC_ERR_UMODEUNKNOWNFLAG ":Unknown MODE flag"
|
||||
502 IRC_ERR_USERSDONTMATCH ":Cannot change mode for other users"
|
161
kike.c
161
kike.c
|
@ -22,6 +22,7 @@
|
|||
#define PROGRAM_VERSION "alpha"
|
||||
|
||||
#include "common.c"
|
||||
#include "kike-replies.c"
|
||||
#include <nl_types.h>
|
||||
|
||||
// --- Configuration (application-specific) ------------------------------------
|
||||
|
@ -861,166 +862,6 @@ client_set_ping_timer (struct client *c)
|
|||
|
||||
// --- IRC command handling ----------------------------------------------------
|
||||
|
||||
enum
|
||||
{
|
||||
IRC_RPL_WELCOME = 1,
|
||||
IRC_RPL_YOURHOST = 2,
|
||||
IRC_RPL_CREATED = 3,
|
||||
IRC_RPL_MYINFO = 4,
|
||||
|
||||
IRC_RPL_UMODEIS = 221,
|
||||
IRC_RPL_LUSERCLIENT = 251,
|
||||
IRC_RPL_LUSEROP = 252,
|
||||
IRC_RPL_LUSERUNKNOWN = 253,
|
||||
IRC_RPL_LUSERCHANNELS = 254,
|
||||
IRC_RPL_LUSERME = 255,
|
||||
|
||||
IRC_RPL_AWAY = 301,
|
||||
IRC_RPL_USERHOST = 302,
|
||||
IRC_RPL_ISON = 303,
|
||||
IRC_RPL_UNAWAY = 305,
|
||||
IRC_RPL_NOWAWAY = 306,
|
||||
IRC_RPL_WHOISUSER = 311,
|
||||
IRC_RPL_WHOISSERVER = 312,
|
||||
IRC_RPL_WHOISOPERATOR = 313,
|
||||
IRC_RPL_ENDOFWHO = 315,
|
||||
IRC_RPL_WHOISIDLE = 317,
|
||||
IRC_RPL_ENDOFWHOIS = 318,
|
||||
IRC_RPL_WHOISCHANNELS = 319,
|
||||
IRC_RPL_LIST = 322,
|
||||
IRC_RPL_LISTEND = 323,
|
||||
IRC_RPL_CHANNELMODEIS = 324,
|
||||
IRC_RPL_NOTOPIC = 331,
|
||||
IRC_RPL_TOPIC = 332,
|
||||
IRC_RPL_INVITELIST = 346,
|
||||
IRC_RPL_ENDOFINVITELIST = 347,
|
||||
IRC_RPL_EXCEPTLIST = 348,
|
||||
IRC_RPL_ENDOFEXCEPTLIST = 349,
|
||||
IRC_RPL_VERSION = 351,
|
||||
IRC_RPL_WHOREPLY = 352,
|
||||
IRC_RPL_NAMREPLY = 353,
|
||||
IRC_RPL_ENDOFNAMES = 366,
|
||||
IRC_RPL_BANLIST = 367,
|
||||
IRC_RPL_ENDOFBANLIST = 368,
|
||||
IRC_RPL_MOTD = 372,
|
||||
IRC_RPL_MOTDSTART = 375,
|
||||
IRC_RPL_ENDOFMOTD = 376,
|
||||
IRC_RPL_TIME = 391,
|
||||
|
||||
IRC_ERR_NOSUCHNICK = 401,
|
||||
IRC_ERR_NOSUCHSERVER = 402,
|
||||
IRC_ERR_NOSUCHCHANNEL = 403,
|
||||
IRC_ERR_CANNOTSENDTOCHAN = 404,
|
||||
IRC_ERR_NOORIGIN = 409,
|
||||
IRC_ERR_NORECIPIENT = 411,
|
||||
IRC_ERR_NOTEXTTOSEND = 412,
|
||||
IRC_ERR_UNKNOWNCOMMAND = 421,
|
||||
IRC_ERR_NOMOTD = 422,
|
||||
IRC_ERR_NOADMININFO = 423,
|
||||
IRC_ERR_NONICKNAMEGIVEN = 431,
|
||||
IRC_ERR_ERRONEOUSNICKNAME = 432,
|
||||
IRC_ERR_NICKNAMEINUSE = 433,
|
||||
IRC_ERR_USERNOTINCHANNEL = 441,
|
||||
IRC_ERR_NOTONCHANNEL = 442,
|
||||
IRC_ERR_SUMMONDISABLED = 445,
|
||||
IRC_ERR_USERSDISABLED = 446,
|
||||
IRC_ERR_NOTREGISTERED = 451,
|
||||
IRC_ERR_NEEDMOREPARAMS = 461,
|
||||
IRC_ERR_ALREADYREGISTERED = 462,
|
||||
IRC_ERR_KEYSET = 467,
|
||||
IRC_ERR_CHANNELISFULL = 471,
|
||||
IRC_ERR_UNKNOWNMODE = 472,
|
||||
IRC_ERR_INVITEONLYCHAN = 473,
|
||||
IRC_ERR_BANNEDFROMCHAN = 474,
|
||||
IRC_ERR_BADCHANNELKEY = 475,
|
||||
IRC_ERR_BADCHANMASK = 476,
|
||||
IRC_ERR_NOPRIVILEGES = 481,
|
||||
IRC_ERR_CHANOPRIVSNEEDED = 482,
|
||||
|
||||
IRC_ERR_UMODEUNKNOWNFLAG = 501,
|
||||
IRC_ERR_USERSDONTMATCH = 502
|
||||
};
|
||||
|
||||
static const char *g_default_replies[] =
|
||||
{
|
||||
[IRC_RPL_WELCOME] = ":Welcome to the Internet Relay Network %s!%s@%s",
|
||||
[IRC_RPL_YOURHOST] = ":Your host is %s, running version %s",
|
||||
[IRC_RPL_CREATED] = ":This server was created %s",
|
||||
[IRC_RPL_MYINFO] = "%s %s %s %s",
|
||||
|
||||
[IRC_RPL_UMODEIS] = "+%s",
|
||||
[IRC_RPL_LUSERCLIENT] = ":There are %d users and %d services on %d servers",
|
||||
[IRC_RPL_LUSEROP] = "%d :operator(s) online",
|
||||
[IRC_RPL_LUSERUNKNOWN] = "%d :unknown connection(s)",
|
||||
[IRC_RPL_LUSERCHANNELS] = "%d :channels formed",
|
||||
[IRC_RPL_LUSERME] = ":I have %d clients and %d servers",
|
||||
|
||||
[IRC_RPL_AWAY] = "%s :%s",
|
||||
[IRC_RPL_USERHOST] = ":%s",
|
||||
[IRC_RPL_ISON] = ":%s",
|
||||
[IRC_RPL_UNAWAY] = ":You are no longer marked as being away",
|
||||
[IRC_RPL_NOWAWAY] = ":You have been marked as being away",
|
||||
[IRC_RPL_WHOISUSER] = "%s %s %s * :%s",
|
||||
[IRC_RPL_WHOISSERVER] = "%s %s :%s",
|
||||
[IRC_RPL_WHOISOPERATOR] = "%s :is an IRC operator",
|
||||
[IRC_RPL_ENDOFWHO] = "%s :End of WHO list",
|
||||
[IRC_RPL_WHOISIDLE] = "%s %d :seconds idle",
|
||||
[IRC_RPL_ENDOFWHOIS] = "%s :End of WHOIS list",
|
||||
[IRC_RPL_WHOISCHANNELS] = "%s :%s",
|
||||
[IRC_RPL_LIST] = "%s %d :%s",
|
||||
[IRC_RPL_LISTEND] = ":End of LIST",
|
||||
[IRC_RPL_CHANNELMODEIS] = "%s +%s",
|
||||
[IRC_RPL_NOTOPIC] = "%s :No topic is set",
|
||||
[IRC_RPL_TOPIC] = "%s :%s",
|
||||
[IRC_RPL_INVITELIST] = "%s %s",
|
||||
[IRC_RPL_ENDOFINVITELIST] = "%s :End of channel invite list",
|
||||
[IRC_RPL_EXCEPTLIST] = "%s %s",
|
||||
[IRC_RPL_ENDOFEXCEPTLIST] = "%s :End of channel exception list",
|
||||
[IRC_RPL_VERSION] = "%s.%d %s :%s",
|
||||
[IRC_RPL_WHOREPLY] = "%s %s %s %s %s %s :%d %s",
|
||||
[IRC_RPL_NAMREPLY] = "%c %s :%s",
|
||||
[IRC_RPL_ENDOFNAMES] = "%s :End of NAMES list",
|
||||
[IRC_RPL_BANLIST] = "%s %s",
|
||||
[IRC_RPL_ENDOFBANLIST] = "%s :End of channel ban list",
|
||||
[IRC_RPL_MOTD] = ":- %s",
|
||||
[IRC_RPL_MOTDSTART] = ":- %s Message of the day - ",
|
||||
[IRC_RPL_ENDOFMOTD] = ":End of MOTD command",
|
||||
[IRC_RPL_TIME] = "%s :%s",
|
||||
|
||||
[IRC_ERR_NOSUCHNICK] = "%s :No such nick/channel",
|
||||
[IRC_ERR_NOSUCHSERVER] = "%s :No such server",
|
||||
[IRC_ERR_NOSUCHCHANNEL] = "%s :No such channel",
|
||||
[IRC_ERR_CANNOTSENDTOCHAN] = "%s :Cannot send to channel",
|
||||
[IRC_ERR_NOORIGIN] = ":No origin specified",
|
||||
[IRC_ERR_NORECIPIENT] = ":No recipient given (%s)",
|
||||
[IRC_ERR_NOTEXTTOSEND] = ":No text to send",
|
||||
[IRC_ERR_UNKNOWNCOMMAND] = "%s: Unknown command",
|
||||
[IRC_ERR_NOMOTD] = ":MOTD File is missing",
|
||||
[IRC_ERR_NOADMININFO] = "%s :No administrative info available",
|
||||
[IRC_ERR_NONICKNAMEGIVEN] = ":No nickname given",
|
||||
[IRC_ERR_ERRONEOUSNICKNAME] = "%s :Erroneous nickname",
|
||||
[IRC_ERR_NICKNAMEINUSE] = "%s :Nickname is already in use",
|
||||
[IRC_ERR_USERNOTINCHANNEL] = "%s %s :They aren't on that channel",
|
||||
[IRC_ERR_NOTONCHANNEL] = "%s :You're not on that channel",
|
||||
[IRC_ERR_SUMMONDISABLED] = ":SUMMON has been disabled",
|
||||
[IRC_ERR_USERSDISABLED] = ":USERS has been disabled",
|
||||
[IRC_ERR_NOTREGISTERED] = ":You have not registered",
|
||||
[IRC_ERR_NEEDMOREPARAMS] = "%s :Not enough parameters",
|
||||
[IRC_ERR_ALREADYREGISTERED] = ":Unauthorized command (already registered)",
|
||||
[IRC_ERR_KEYSET] = "%s :Channel key already set",
|
||||
[IRC_ERR_CHANNELISFULL] = "%s :Cannot join channel (+l)",
|
||||
[IRC_ERR_UNKNOWNMODE] = "%c :is unknown mode char to me for %s",
|
||||
[IRC_ERR_INVITEONLYCHAN] = "%s :Cannot join channel (+i)",
|
||||
[IRC_ERR_BANNEDFROMCHAN] = "%s :Cannot join channel (+b)",
|
||||
[IRC_ERR_BADCHANNELKEY] = "%s :Cannot join channel (+k)",
|
||||
[IRC_ERR_BADCHANMASK] = "%s :Bad Channel Mask",
|
||||
[IRC_ERR_NOPRIVILEGES] = ":Permission Denied- You're not an IRC operator",
|
||||
[IRC_ERR_CHANOPRIVSNEEDED] = "%s :You're not channel operator",
|
||||
|
||||
[IRC_ERR_UMODEUNKNOWNFLAG] = ":Unknown MODE flag",
|
||||
[IRC_ERR_USERSDONTMATCH] = ":Cannot change mode for other users",
|
||||
};
|
||||
|
||||
// XXX: this way we cannot typecheck the arguments, so we must be careful
|
||||
static void
|
||||
irc_send_reply (struct client *c, int id, ...)
|
||||
|
|
Loading…
Reference in New Issue