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/>.
31 void config_set (char *variable
, char *value
)
33 printf ("config -> %s : %s\n", variable
, value
);
35 if (!strcmp (variable
, "nick"))
36 cfg
->nick
= strdup (value
);
37 else if (!strcmp (variable
, "password"))
38 cfg
->password
= strdup (value
);
39 else if (!strcmp (variable
, "server"))
40 cfg
->server
= strdup (value
);
41 else if (!strcmp (variable
, "port"))
42 cfg
->port
= atoi (value
);
45 void config_parse (char *cfgfile
, unsigned cfglen
)
47 unsigned i
= 0, y
= cfglen
, z
= 0;
51 if (cfgfile
[i
] == '\n') {
58 if (cfgfile
[a
+z
] == ' ')
67 memcpy (var
, cfgfile
+z
, a
);
72 memcpy (val
, cfgfile
+z
+a
, i
-z
-a
);
75 config_set (var
, val
);
86 int config_load (char *file
)
88 char *cfgfile
= (char *) malloc (sizeof (char) * DEFAULT_CONFIG_MAXLENGTH
);
94 int fd
= open (file
, O_RDONLY
);
97 printf ("error -> file 'config' not found\n");
101 int cfglen
= read (fd
, cfgfile
, DEFAULT_CONFIG_MAXLENGTH
-1);
104 printf ("error -> something was wrong !\n");
108 cfgfile
[DEFAULT_CONFIG_MAXLENGTH
-1] = '\0';
110 cfg
= (config_t
*) malloc (sizeof (config_t
));
115 config_parse (cfgfile
, (unsigned) cfglen
);
124 /** INIT CONFIG function */
127 if (!config_load (DEFAULT_CONFIG_FILE
))
130 if (!strcmp (cfg
->nick
, "#") || !strcmp (cfg
->password
, "#")) {
131 printf ("WARNING -> Please re-write nick and password variable in 'config' file for autologin\nNOTE -> For register new account use command: /r <nick> <password>\nNOTE -> For more information use command /h for help\n");