Mercurial > hg > nnchat
comparison main.c @ 708:84d7b33c4e83
Change how --help option is handled, and plug some memory leaks in
configuration handling.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 27 Apr 2020 02:45:28 +0300 |
parents | 11eb7c30889e |
children | 93d0e1547842 |
comparison
equal
deleted
inserted
replaced
707:11eb7c30889e | 708:84d7b33c4e83 |
---|---|
90 optProxyEnable = FALSE, | 90 optProxyEnable = FALSE, |
91 setIgnoreMode = FALSE, | 91 setIgnoreMode = FALSE, |
92 optDebug = FALSE, | 92 optDebug = FALSE, |
93 optLogEnable = FALSE, | 93 optLogEnable = FALSE, |
94 optLogDaily = FALSE, | 94 optLogDaily = FALSE, |
95 optOnlyFriendPrv = FALSE; | 95 optOnlyFriendPrv = FALSE, |
96 optShowHelp = FALSE; | |
96 | 97 |
97 char *setHomeDir = NULL, *setConfigDir = NULL, *setProxyURI = NULL; | 98 char *setHomeDir = NULL, *setConfigDir = NULL, *setProxyURI = NULL; |
98 th_llist_t *setIgnoreList = NULL, | 99 th_llist_t *setIgnoreList = NULL, |
99 *setFriendList = NULL, | 100 *setFriendList = NULL, |
100 *setIdleMessages = NULL; | 101 *setIdleMessages = NULL; |
292 BOOL argHandleOpt(const int optN, char *optArg, char *currArg) | 293 BOOL argHandleOpt(const int optN, char *optArg, char *currArg) |
293 { | 294 { |
294 switch (optN) | 295 switch (optN) |
295 { | 296 { |
296 case 0: | 297 case 0: |
297 argShowHelp(); | 298 optShowHelp = TRUE; |
298 exit(0); | |
299 break; | 299 break; |
300 | 300 |
301 case 1: | 301 case 1: |
302 th_verbosity++; | 302 th_verbosity++; |
303 break; | 303 break; |
1940 nn_log_close(win); | 1940 nn_log_close(win); |
1941 return nn_log_open(win); | 1941 return nn_log_open(win); |
1942 } | 1942 } |
1943 | 1943 |
1944 | 1944 |
1945 void nn_cfg_free(th_cfgitem_t *node) | |
1946 { | |
1947 switch (node->type) | |
1948 { | |
1949 case ITEM_STRING: | |
1950 th_free(*(node->v.val_str)); | |
1951 break; | |
1952 | |
1953 case ITEM_STRING_LIST: | |
1954 th_llist_free_func_data(*(node->v.list), th_free); | |
1955 break; | |
1956 } | |
1957 } | |
1958 | |
1959 | |
1945 int main(int argc, char *argv[]) | 1960 int main(int argc, char *argv[]) |
1946 { | 1961 { |
1947 char *tmpStr; | 1962 char *tmpStr; |
1948 int index, updateCount = 0, ret; | 1963 int index, updateCount = 0, ret; |
1949 BOOL argsOK, colorSet = FALSE; | 1964 BOOL argsOK, colorSet = FALSE; |
2070 if (setProxyURI && !argHandleProxyURI(setProxyURI)) | 2085 if (setProxyURI && !argHandleProxyURI(setProxyURI)) |
2071 goto err_exit; | 2086 goto err_exit; |
2072 | 2087 |
2073 optNickSep = optNickSepStr ? optNickSepStr[0] : SET_NICK_SEPARATOR; | 2088 optNickSep = optNickSepStr ? optNickSepStr[0] : SET_NICK_SEPARATOR; |
2074 | 2089 |
2075 setBrowser = getenv("BROWSER"); | 2090 if (setBrowser == NULL) |
2076 if (setBrowser == NULL || setBrowser[0] == 0) | 2091 { |
2077 setBrowser = "firefox"; | 2092 setBrowser = getenv("BROWSER"); |
2093 if (setBrowser == NULL || setBrowser[0] == 0) | |
2094 setBrowser = "firefox"; | |
2095 | |
2096 setBrowser = th_strdup(setBrowser); | |
2097 } | |
2078 | 2098 |
2079 if (optLogPath == NULL && setHomeDir != NULL) | 2099 if (optLogPath == NULL && setHomeDir != NULL) |
2080 { | 2100 { |
2081 optLogPath = th_strdup_printf("%s%c%s%c", | 2101 optLogPath = th_strdup_printf("%s%c%s%c", |
2082 setHomeDir, TH_DIR_SEPARATOR_CHR, SET_LOG_DIR, TH_DIR_SEPARATOR_CHR); | 2102 setHomeDir, TH_DIR_SEPARATOR_CHR, SET_LOG_DIR, TH_DIR_SEPARATOR_CHR); |
2124 argHandleOpt, argHandleFile, 0); | 2144 argHandleOpt, argHandleFile, 0); |
2125 | 2145 |
2126 if (optUserNameCmd != NULL) | 2146 if (optUserNameCmd != NULL) |
2127 { | 2147 { |
2128 THMSG(1, "Username set on commandline.\n"); | 2148 THMSG(1, "Username set on commandline.\n"); |
2129 optUserName = optUserNameCmd; | 2149 th_pstr_cpy(&optUserName, optUserNameCmd); |
2130 optPassword = optPasswordCmd; | 2150 th_pstr_cpy(&optPassword, optPasswordCmd); |
2131 } | 2151 } |
2132 | 2152 |
2133 if (!argsOK) | 2153 if (!argsOK) |
2134 return -2; | 2154 goto err_exit; |
2155 | |
2156 if (optShowHelp) | |
2157 { | |
2158 argShowHelp(); | |
2159 goto err_exit; | |
2160 } | |
2135 | 2161 |
2136 // Allocate userhash | 2162 // Allocate userhash |
2137 if ((nnUsers = nn_userhash_new()) == NULL) | 2163 if ((nnUsers = nn_userhash_new()) == NULL) |
2138 { | 2164 { |
2139 THERR("Could not allocate userhash. Fatal error.\n"); | 2165 THERR("Could not allocate userhash. Fatal error.\n"); |
2140 return -105; | 2166 goto err_exit; |
2141 } | 2167 } |
2142 | 2168 |
2143 // If no idle messages are set, add default | 2169 // If no idle messages are set, add default |
2144 if (setIdleMessages == NULL) | 2170 if (setIdleMessages == NULL) |
2145 { | 2171 { |
2353 clearEditState(&editState); | 2379 clearEditState(&editState); |
2354 tmp = nnwin_prompt_requester(FALSE, &editState, processUserPrompt, updateUserPrompt); | 2380 tmp = nnwin_prompt_requester(FALSE, &editState, processUserPrompt, updateUserPrompt); |
2355 th_free(tmp); | 2381 th_free(tmp); |
2356 } | 2382 } |
2357 | 2383 |
2358 th_cfg_free(cfg); | |
2359 th_free(setHomeDir); | 2384 th_free(setHomeDir); |
2360 th_free(setConfigDir); | 2385 th_free(setConfigDir); |
2361 th_llist_free_func_data(setIdleMessages, th_free); | |
2362 nn_userhash_free(nnUsers); | 2386 nn_userhash_free(nnUsers); |
2363 nn_editbuf_free(editBuf); | 2387 nn_editbuf_free(editBuf); |
2388 | |
2389 th_cfg_free(cfg, nn_cfg_free); | |
2364 | 2390 |
2365 for (index = 0; index <= SET_MAX_HISTORY; index++) | 2391 for (index = 0; index <= SET_MAX_HISTORY; index++) |
2366 nn_editbuf_free(editHistBuf[index]); | 2392 nn_editbuf_free(editHistBuf[index]); |
2367 | 2393 |
2368 nnwin_shutdown(); | 2394 nnwin_shutdown(); |