Cleanup in elf.c with .bss section clean; adm command mounts cdrom instead of floppy...
[ZeXOS.git] / apps / irc / main.c
blob038d92eb471a64191ca662f7ce4846203f0ad51f
1 /*
2 * ZeX/OS
3 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <stdio.h>
21 #include <string.h>
22 #include <stdlib.h>
23 #include "commands.h"
24 #include "config.h"
25 #include "proto.h"
26 #include "net.h"
28 CONFIG config;
30 extern char *buf;
32 int pick_nick ()
34 char nick[64];
36 printf ("Pick a nick: ");
38 scanf ("%s", nick);
40 printf ("\nPlease wait ..\n");
42 config.nick = strdup (nick);
44 return 1;
47 int init (char *address, int port, int flags)
49 pick_nick ();
51 if (!init_net (address, port, flags))
52 return 0;
54 config.server = address;
55 config.server_len = strlen (address);
57 if (!init_proto ())
58 return 0;
60 if (!commands_init ())
61 return 0;
63 return 1;
66 int loop ()
68 while (1) {
69 if (!net_loop ())
70 return 0;
72 if (!proto_parser ())
73 return 0;
75 if (!commands_get ())
76 return 0;
77 #ifndef LINUX
78 schedule ();
79 #endif
82 return 1;
85 int quit ()
87 net_close ();
89 printf ("Bye !\n");
91 return 1;
94 void syntax ()
96 printf ("irc: <address> <port> [-6]\nGNU/GPL3 - Coded by ZeXx86\n");
99 int main (int argc, char **argv)
101 if (argc == 1) {
102 syntax ();
103 return 0;
106 int port = 0;
107 int proto = 0;
109 if (argc > 2) {
110 port = atoi (argv[2]);
112 if (argc > 3)
113 if (!strncmp (argv[argc-1], "-6", 2)) {
114 proto |= NET_IPV6;
115 printf ("> IPv6 mode\n");
119 if (!port)
120 port = 6667; /* set default port, when user not specify any */
122 printf ("-= IRC Client =-\n");
124 if (!init (argv[1], port, proto)) {
125 printf ("ERROR -> init () failed\n");
126 return -1;
129 loop ();
131 quit ();
133 /* free buffers */
134 free (buf);
135 free (config.nick);
136 free (config.server);
138 if (config.channel_len)
139 free (config.channel);
141 return 0;