# HG changeset patch # User mikael # Date 1115373524 0 # Node ID 7604e3cdbb86ab3984ae2f1531154c86b20f0902 # Parent 4ce9ff808baa35b7f09000f6123e24f70410c803 [/trunk] Changeset 200 by mikael * Add a cfg_read_int() function... diff -r 4ce9ff808baa -r 7604e3cdbb86 mcabber/src/TODO --- a/mcabber/src/TODO Fri May 06 09:35:40 2005 +0000 +++ b/mcabber/src/TODO Fri May 06 09:58:44 2005 +0000 @@ -16,7 +16,6 @@ * Add a function in hbuf ~previous_persistent(hbuf *top) (to avoid loosing the top variable on a resize). * Show number of online contacts in folded groups -* Add a cfg_read_int() function * Buddy buffer in full width (handy for cut'n paste!) * Commands! :-) diff -r 4ce9ff808baa -r 7604e3cdbb86 mcabber/src/main.c --- a/mcabber/src/main.c Fri May 06 09:35:40 2005 +0000 +++ b/mcabber/src/main.c Fri May 06 09:58:44 2005 +0000 @@ -87,15 +87,14 @@ int main(int argc, char **argv) { char *configFile = NULL; - char *username, *password, *resource; - char *servername, *portstring; + char *username, *password, *resource, *servername; char *jid; - char *optstring, *optstring2; + char *optstring; int optval, optval2; + int ssl; int key; unsigned int port; unsigned int ping; - int ssl; int ret = 0; unsigned int refresh = 0; @@ -134,13 +133,12 @@ if (configFile) g_free(configFile); optstring = cfg_read("debug"); - if (optstring) - ut_InitDebug(1, optstring); + if (optval) ut_InitDebug(1, optstring); servername = cfg_read("server"); - username = cfg_read("username"); - password = cfg_read("password"); - resource = cfg_read("resource"); + username = cfg_read("username"); + password = cfg_read("password"); + resource = cfg_read("resource"); if (!servername) { printf("Server name has not been specified in the config file!\n"); @@ -168,22 +166,16 @@ ut_WriteLog("Drawing main window...\n"); scr_DrawMainWindow(TRUE); - optstring = cfg_read("logging"); - optstring2 = cfg_read("load_logs"); - optval = (optstring && (atoi(optstring) > 0)); - optval2 = (optstring2 && (atoi(optstring2) > 0)); + optval = (cfg_read_int("logging") > 0); + optval2 = (cfg_read_int("load_logs") > 0); if (optval || optval2) hlog_enable(optval, cfg_read("logging_dir"), optval2); if ((optstring = cfg_read("events_command")) != NULL) hk_ext_cmd_init(optstring); - ssl = 0; - optstring = cfg_read("ssl"); - if (optstring && (atoi(optstring) > 0)) - ssl = 1; - portstring = cfg_read("port"); - port = (portstring != NULL) ? (unsigned int) atoi(portstring) : 0; + ssl = (cfg_read_int("ssl") > 0); + port = (unsigned int) cfg_read_int("port"); /* Connect to server */ ut_WriteLog("Connecting to server: %s:%d\n", servername, port); @@ -205,8 +197,7 @@ jb_set_keepalive_delay(ping); ut_WriteLog("Ping interval stablished: %d secs\n", ping); - optstring = cfg_read("hide_offline_buddies"); - if (optstring && (atoi(optstring) > 0)) + if (cfg_read_int("hide_offline_buddies") > 0) buddylist_set_hide_offline_buddies(TRUE); /* Initialize commands system */ diff -r 4ce9ff808baa -r 7604e3cdbb86 mcabber/src/parsecfg.c --- a/mcabber/src/parsecfg.c Fri May 06 09:35:40 2005 +0000 +++ b/mcabber/src/parsecfg.c Fri May 06 09:58:44 2005 +0000 @@ -115,3 +115,15 @@ } return NULL; } + +int cfg_read_int(char *key) +{ + char *optval; + + optval = cfg_read(key); + + if (optval) + return atoi(optval); + + return 0; +} diff -r 4ce9ff808baa -r 7604e3cdbb86 mcabber/src/parsecfg.h --- a/mcabber/src/parsecfg.h Fri May 06 09:35:40 2005 +0000 +++ b/mcabber/src/parsecfg.h Fri May 06 09:58:44 2005 +0000 @@ -3,5 +3,6 @@ int cfg_file(char *filename); char *cfg_read(char *key); +int cfg_read_int(char *key); #endif