Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
OOP in C!
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
Reply to thread
Message
[QUOTE="Stephen Sprunk, post: 1713240"] Grossly simplified, this is how the core parsing in ircd works: static void parse_foo(char *user, char *channel, char *command); static void parse_bar(char *user, char *channel, char *command); static void parse_baz(char *user, char *channel, char *command); static void parse_zot(char *user, char *channel, char *command); struct parser_record { char *command; void (*parser)(char *, char *, char *); } struct parser_record parser_table_user[] = { { "FOO", parse_foo }, { "BAR", parse_bar }, { "BAZ", parse_baz }, { NULL, NULL} } struct parser_record parser_table_operator[] = { { "FOO", parse_foo }, { "BAZ", parse_baz }, { "ZOT", parse_zot }, { NULL, NULL} } int parse_main(struct parser_record parsers[], char *user, char *channel, char *command, char *arguments) { int i; for (i=0; parsers[i].command; i++) if (!strcmp(parsers[i].command, command)) { parsers[i].parser(user, channel, arguments); return 0; } return -1; } I know there's probably typos in there, but that's the gist of it. Since the command selector is a string, it can't be used in a switch statement, and keeping the list of commands and their respective parsers in an array also makes it very easy to add and remove commands without touching the core logic. And, since the list of commands is stored outside said logic, it also allows different users to get a different list of valid commands (or the same commands pointing to different parsers) just by passing in a different array to the same core logic. S[/i][/i][/i] [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
OOP in C!
Top