diff options
author | Bertrand Jacquin (Beber) <beber.mailing@gmail.com> | 2006-04-30 03:01:03 +0200 |
---|---|---|
committer | beber <beber@meathook.melee> | 2006-04-30 03:01:03 +0200 |
commit | 20e7c8f2225cb5861317a7aef8998362fdd35b25 (patch) | |
tree | d026bd0cd0cd6d97bd19084213c7ce5c29628310 /src/espik_irc.c | |
parent | oops, forgot to change get_version in m4 macros (diff) | |
download | espik-20e7c8f2225cb5861317a7aef8998362fdd35b25.tar.xz |
indent fixe
Diffstat (limited to 'src/espik_irc.c')
-rw-r--r-- | src/espik_irc.c | 354 |
1 files changed, 177 insertions, 177 deletions
diff --git a/src/espik_irc.c b/src/espik_irc.c index ff58dea..de418ca 100644 --- a/src/espik_irc.c +++ b/src/espik_irc.c @@ -12,259 +12,259 @@ #include "espik_net.h" #include "espik.h" -char* current_chan; +char* current_chan; typedef struct { - char* cmd_name; - char* (*format) (char *dest, char *msg); + char* cmd_name; + char* (*format) (char *dest, char *msg); } cmd_t; -cmd_t cmd_tab[] = { - { "JOIN", irc_join }, - { "PART", irc_part }, - { "PRIVMSG", irc_privmsg }, - { "QUIT", irc_quit }, - { "RAW", irc_raw }, - { "NICK", irc_nick }, -/* { "ACTION", irc_action }, */ - { 0, 0 } +cmd_t cmd_tab[] = { + { "JOIN", irc_join }, + { "PART", irc_part }, + { "PRIVMSG", irc_privmsg }, + { "QUIT", irc_quit }, + { "RAW", irc_raw }, + { "NICK", irc_nick }, +/* { "ACTION", irc_action }, */ + { 0, 0 } }; /* Cut the commandline in two string * 1: The first word * 2: The rest (without any trailer whitespace between firt and rest). */ -char** separate_commandline (char *msg) +char** separate_commandline (char *msg) { - unsigned int len; - char** two_words; + unsigned int len; + char** two_words; - /* Yes, do nothing, just get len ! */ - for (len = 0 ; msg[len] != ' ' && msg[len] != '\t' ; len++); + /* Yes, do nothing, just get len ! */ + for (len = 0 ; msg[len] != ' ' && msg[len] != '\t' ; len++); - two_words = malloc (2 * sizeof(char*)); + two_words = malloc (2 * sizeof(char*)); - msg[len] = '\0'; - two_words[0] = msg; + msg[len] = '\0'; + two_words[0] = msg; - do - { - two_words[1] = msg + ++len; - } - while (*two_words[1] == ' ' || *two_words[1] == '\t'); + do + { + two_words[1] = msg + ++len; + } + while (*two_words[1] == ' ' || *two_words[1] == '\t'); - return (two_words); + return (two_words); } #if 0 -void string_upper (char *str) +void string_upper (char *str) { - unsigned int len, i; - espik_enter(); - - len = strlen (str); - - for (i = 0; i < len; i++) - { - if (str[i] >= 0x61 && str[i] <= 0x7A) - str[i] -= 0x20; - } - printf ("string_upper: %s", str); - espik_leave(); + unsigned int len, i; + espik_enter(); + + len = strlen (str); + + for (i = 0; i < len; i++) + { + if (str[i] >= 0x61 && str[i] <= 0x7A) + str[i] -= 0x20; + } + printf ("string_upper: %s", str); + espik_leave(); } #endif -unsigned short sendmsg_len (char* msg) +unsigned short sendmsg_len (char* msg) { - return (strlen (msg) + 2); + return (strlen (msg) + 2); } -buf_t make_buffer(int len) +buf_t make_buffer(int len) { - buf_t buf; + buf_t buf; - buf.buf = malloc (len); - buf.len = len + 1; /* Alloc trailing \0 */ + buf.buf = malloc (len); + buf.len = len + 1; /* Alloc trailing \0 */ - return (buf); + return (buf); } -char* irc_privmsg (char* chan, char* msg) +char* irc_privmsg (char* chan, char* msg) { - buf_t out; + buf_t out; - out = make_buffer (strlen ("PRIVMSG") + 1 /* "PRIVMSG " */ - + strlen (chan) + 2 /* ":<channel> "*/ - + strlen (msg)); /* "<msg>EOF" */ + out = make_buffer (strlen ("PRIVMSG") + 1 /* "PRIVMSG " */ + + strlen (chan) + 2 /* ":<channel> "*/ + + strlen (msg)); /* "<msg>EOF" */ - snprintf (out.buf, out.len, "PRIVMSG %s :%s", chan, msg); + snprintf (out.buf, out.len, "PRIVMSG %s :%s", chan, msg); - free (msg); - return (out.buf); + free (msg); + return (out.buf); } -char* irc_join (char* chan __UNUSED__, char* msg) +char* irc_join (char* chan __UNUSED__, char* msg) { - buf_t out; - - /* Could also by '&' and so one ... - * have to look on RFC, dev will be done with # only */ - if (msg[0] != '#') - { - printf ("%s is not a channel", msg); - printf ("Usage: /JOIN #channel"); - return (0); - } - - out = make_buffer (strlen ("JOIN") + 1 /* "JOIN " */ - + strlen (msg)); /* "<msg>EOF" */ - - snprintf (out.buf, out.len, "JOIN %s", msg); - - free (msg); - return (out.buf); + buf_t out; + + /* Could also by '&' and so one ... + * have to look on RFC, dev will be done with # only */ + if (msg[0] != '#') + { + printf ("%s is not a channel", msg); + printf ("Usage: /JOIN #channel"); + return (0); + } + + out = make_buffer (strlen ("JOIN") + 1 /* "JOIN " */ + + strlen (msg)); /* "<msg>EOF" */ + + snprintf (out.buf, out.len, "JOIN %s", msg); + + free (msg); + return (out.buf); } -char* irc_part (char* chan, char* msg) +char* irc_part (char* chan, char* msg) { - buf_t out; + buf_t out; - if (msg[0] != '#') - { - out = make_buffer (strlen ("PART") + 1 /* "PART " */ - + strlen (chan) + 2 /* ":<chan> " */ - + strlen (msg)); /* "<msg>EOF" */ + if (msg[0] != '#') + { + out = make_buffer (strlen ("PART") + 1 /* "PART " */ + + strlen (chan) + 2 /* ":<chan> " */ + + strlen (msg)); /* "<msg>EOF" */ - snprintf (out.buf, out.len, "PART %s :%s", chan, msg); - } - else - { - char** sep; + snprintf (out.buf, out.len, "PART %s :%s", chan, msg); + } + else + { + char** sep; - sep = separate_commandline (msg); + sep = separate_commandline (msg); - out = make_buffer (strlen ("PART") + 1 /* "PART " */ - + strlen (sep[0]) + 2 /* ":<chan> "*/ - + strlen (sep[1])); /* "<msg>EOF"*/ + out = make_buffer (strlen ("PART") + 1 /* "PART " */ + + strlen (sep[0]) + 2 /* ":<chan> "*/ + + strlen (sep[1])); /* "<msg>EOF"*/ - snprintf (out.buf, out.len, "PART %s :%s", sep[0], sep[1]); - } + snprintf (out.buf, out.len, "PART %s :%s", sep[0], sep[1]); + } - free (msg); - return (out.buf); + free (msg); + return (out.buf); } -char* irc_quit (char* chan __UNUSED__, char* msg) +char* irc_quit (char* chan __UNUSED__, char* msg) { - buf_t out; + buf_t out; - out = make_buffer (strlen ("QUIT") + 2 /* "QUIT :" */ - + strlen (msg)); /* "<msg>EOF" */ + out = make_buffer (strlen ("QUIT") + 2 /* "QUIT :" */ + + strlen (msg)); /* "<msg>EOF" */ - snprintf (out.buf, out.len, "QUIT :%s", msg); + snprintf (out.buf, out.len, "QUIT :%s", msg); - printf ("msg : %s\nout: %s", msg, out.buf); + printf ("msg : %s\nout: %s", msg, out.buf); - /* - espik_raw_send (out); - espik_con_shutdown (); + /* + espik_raw_send (out); + espik_con_shutdown (); - irc_disconnect(sock); - */ - free (msg); + irc_disconnect(sock); + */ + free (msg); - return (out.buf); + return (out.buf); } -char* irc_raw (char* chan __UNUSED__, char* msg) +char* irc_raw (char* chan __UNUSED__, char* msg) { - return (msg); + return (msg); } -char* irc_nick (char* chan __UNUSED__, char* nick) +char* irc_nick (char* chan __UNUSED__, char* nick) { - buf_t out; + buf_t out; - out = make_buffer (strlen ("NICK") + 1 /* "NICK " */ - + strlen (nick)); /* "<nick>EOF" */ + out = make_buffer (strlen ("NICK") + 1 /* "NICK " */ + + strlen (nick)); /* "<nick>EOF" */ - snprintf (out.buf, out.len, "NICK %s", nick); + snprintf (out.buf, out.len, "NICK %s", nick); - printf ("NICK CHANGED REQUEST: %s", nick); + printf ("NICK CHANGED REQUEST: %s", nick); - return (out.buf); + return (out.buf); } #if 0 -Ecore_Con_Server* irc_connect (char* host __UNUSED__, int port __UNUSED__) +Ecore_Con_Server* irc_connect (char* host __UNUSED__, int port __UNUSED__) { - espik_enter(); - espik_leave(); - return (NULL); + espik_enter(); + espik_leave(); + return (NULL); } -void irc_disconnect (Ecore_Con_Server *sock) +void irc_disconnect (Ecore_Con_Server *sock) { - espik_enter(); - printf ("> irc_disconnect"); - ecore_main_loop_quit (); - printf ("< irc_disconnect"); - espik_leave(); + espik_enter(); + printf ("> irc_disconnect"); + ecore_main_loop_quit (); + printf ("< irc_disconnect"); + espik_leave(); } #endif -char* irc_send (char* msg) +char* irc_send (char* msg) { - char* out; - - out = NULL; - - current_chan = "#e.fr"; - - if (msg[0] == '/') - { - char** cmd_and_message; - cmd_t* cmd; - - cmd_and_message = separate_commandline (msg + 1); - - /* - printf ("irc_send: <separate_commandline"); - */ - - /* - string_upper (cmd_and_message[0]); - */ - - for (cmd = cmd_tab; cmd->cmd_name != 0; cmd++) - { - if ((strcasecmp (cmd_and_message[0], cmd->cmd_name)) == 0) - { - out = cmd->format (current_chan, - cmd_and_message[1]); - free (msg); - /* Why do job after found the good to do ? */ - break; - } - } - if (!out) - { - printf ("%s is not a know command", - cmd_and_message[0]); - return (0); - } - } - else - out = irc_privmsg (current_chan, msg); - - if (!out) - { - free (msg); - return (0); - } - - printf ("%s", out); - - return (out); + char* out; + + out = NULL; + + current_chan = "#e.fr"; + + if (msg[0] == '/') + { + char** cmd_and_message; + cmd_t* cmd; + + cmd_and_message = separate_commandline (msg + 1); + + /* + printf ("irc_send: <separate_commandline"); + */ + + /* + string_upper (cmd_and_message[0]); + */ + + for (cmd = cmd_tab; cmd->cmd_name != 0; cmd++) + { + if ((strcasecmp (cmd_and_message[0], cmd->cmd_name)) == 0) + { + out = cmd->format (current_chan, + cmd_and_message[1]); + free (msg); + /* Why do job after found the good to do ? */ + break; + } + } + if (!out) + { + printf ("%s is not a know command", + cmd_and_message[0]); + return (0); + } + } + else + out = irc_privmsg (current_chan, msg); + + if (!out) + { + free (msg); + return (0); + } + + printf ("%s", out); + + return (out); } |