*** functions.c.orig Thu Apr 6 19:39:38 2000 --- functions.c Tue May 2 08:22:15 2000 *************** *** 778,783 **** --- 778,791 ---- #define RETURN_STR(x) return m_strdup((x) ? (x) : EMPTY) #define RETURN_INT(x) return m_strdup(ltoa((x))) + /* + * XXXX REALLY REALLY REALLY REALLY REALLY REALLY REALLY IMPORTANT! XXXX + * + * Don't ever Ever EVER pass a function call to the RETURN_* macros. + * They _WILL_ evaluate the term twice, and for some function calls, + * that can result in a memory leak, or worse. + */ + #define BUILT_IN_FUNCTION(x, y) static char * x (char * y) /* *************** *** 1359,1364 **** --- 1367,1373 ---- BUILT_IN_FUNCTION(function_channels, input) { int server = from_server; + char * retval; if (isdigit(*input)) GET_INT_ARG(server, input) *************** *** 1371,1377 **** server = window->server; } ! RETURN_MSTR(create_channel_list(server)); } BUILT_IN_FUNCTION(function_servers, input) --- 1380,1387 ---- server = window->server; } ! retval = create_channel_list(server); ! RETURN_MSTR(retval); } BUILT_IN_FUNCTION(function_servers, input) *************** *** 1380,1386 **** char *retval = NULL; if (input || *input) ! RETURN_MSTR(create_server_list()); for (count = 0; count < number_of_servers; count++) { --- 1390,1399 ---- char *retval = NULL; if (input || *input) ! { ! retval = create_server_list(); ! RETURN_MSTR(retval); ! } for (count = 0; count < number_of_servers; count++) { *************** *** 3342,3351 **** { int wordc; char **wordl; ! wordc = splitw(words, &wordl); qsort((void *)wordl, wordc, sizeof(char *), num_sort_it); ! RETURN_MSTR(unsplitw(&wordl, wordc)); } --- 3355,3367 ---- { int wordc; char **wordl; + char *retval; ! if (!(wordc = splitw(words, &wordl))) ! RETURN_EMPTY; qsort((void *)wordl, wordc, sizeof(char *), num_sort_it); ! retval = unsplitw(&wordl, wordc); ! RETURN_MSTR(retval); } *************** *** 3538,3550 **** BUILT_IN_FUNCTION(function_status, word) { ! unsigned window_refnum; ! int status_line; GET_INT_ARG(window_refnum, word); GET_INT_ARG(status_line, word); ! ! RETURN_STR(get_status_by_refnum(window_refnum, status_line)); } /* --- 3554,3567 ---- BUILT_IN_FUNCTION(function_status, word) { ! unsigned window_refnum; ! int status_line; ! char * retval; GET_INT_ARG(window_refnum, word); GET_INT_ARG(status_line, word); ! retval = get_status_by_refnum(window_refnum, status_line); ! RETURN_STR(retval); } /* *************** *** 3572,3578 **** */ if (arg1 && is_channel(arg1)) { ! int servnum = -1; char *chan, *serv = NULL; Window *winp = NULL; /* XXXX */ --- 3589,3595 ---- */ if (arg1 && is_channel(arg1)) { ! int servnum = from_server; char *chan, *serv = NULL; Window *winp = NULL; /* XXXX */ *************** *** 3681,3696 **** BUILT_IN_FUNCTION(function_winbound, input) { Window *foo; ! char *stuff; if (!(stuff = new_next_arg(input, &input))) RETURN_EMPTY; if (my_atol(stuff) && (foo = get_window_by_refnum((unsigned)my_atol(stuff)))) ! RETURN_STR(get_bound_channel(foo)); else if ((foo = get_window_by_name(stuff))) ! RETURN_STR(get_bound_channel(foo)); else if ((foo = get_window_bound_channel(stuff))) ! RETURN_STR(get_refnum_by_window(foo)); RETURN_EMPTY; } --- 3698,3723 ---- BUILT_IN_FUNCTION(function_winbound, input) { Window *foo; ! char * stuff; ! char * retval; if (!(stuff = new_next_arg(input, &input))) RETURN_EMPTY; if (my_atol(stuff) && (foo = get_window_by_refnum((unsigned)my_atol(stuff)))) ! { ! retval = get_bound_channel(foo); ! RETURN_STR(retval); ! } else if ((foo = get_window_by_name(stuff))) ! { ! retval = get_bound_channel(foo); ! RETURN_STR(retval); ! } else if ((foo = get_window_bound_channel(stuff))) ! { ! retval = get_refnum_by_window(foo); ! RETURN_STR(retval); ! } RETURN_EMPTY; } *************** *** 3799,3804 **** --- 3826,3832 ---- { char * servdesc; int refnum; + const char * retval; if (*input) { *************** *** 3812,3818 **** else RETURN_EMPTY; ! RETURN_STR(get_server_nickname(refnum)); } BUILT_IN_FUNCTION(function_winnames, input) --- 3840,3847 ---- else RETURN_EMPTY; ! retval = get_server_nickname(refnum); ! RETURN_STR(retval); } BUILT_IN_FUNCTION(function_winnames, input) *************** *** 4021,4027 **** */ BUILT_IN_FUNCTION(function_igmask, input) { ! RETURN_MSTR(get_ignores_by_pattern(input, 0)); } /* --- 4050,4058 ---- */ BUILT_IN_FUNCTION(function_igmask, input) { ! char * retval; ! retval = get_ignores_by_pattern(input, 0); ! RETURN_MSTR(retval); } /* *************** *** 4032,4038 **** */ BUILT_IN_FUNCTION(function_rigmask, input) { ! RETURN_MSTR(get_ignores_by_pattern(input, 1)); } --- 4063,4071 ---- */ BUILT_IN_FUNCTION(function_rigmask, input) { ! char * retval; ! retval = get_ignores_by_pattern(input, 1); ! RETURN_MSTR(retval); } *************** *** 4642,4647 **** --- 4675,4681 ---- { Window *win; char *desc; + char * retval; if (input && *input) { *************** *** 4654,4670 **** if (!win) RETURN_EMPTY; ! RETURN_STR(bits_to_lastlog_level(win->window_level)); } BUILT_IN_FUNCTION(function_igtype, input) { ! RETURN_STR(get_ignore_types_by_pattern(input)); } BUILT_IN_FUNCTION(function_rigtype, input) { ! RETURN_MSTR(get_ignore_patterns_by_type(input)); } BUILT_IN_FUNCTION(function_getuid, input) --- 4688,4709 ---- if (!win) RETURN_EMPTY; ! retval = bits_to_lastlog_level(win->window_level); ! RETURN_STR(retval); } BUILT_IN_FUNCTION(function_igtype, input) { ! char *retval; ! retval = get_ignore_types_by_pattern(input); ! RETURN_STR(retval); } BUILT_IN_FUNCTION(function_rigtype, input) { ! char *retval; ! retval = get_ignore_patterns_by_type(input); ! RETURN_MSTR(retval); } BUILT_IN_FUNCTION(function_getuid, input) *************** *** 4680,4689 **** BUILT_IN_FUNCTION(function_getlogin, input) { #ifdef HAVE_GETLOGIN ! RETURN_STR(getlogin()); #else ! RETURN_STR(getenv("LOGNAME")); #endif } BUILT_IN_FUNCTION(function_getpgrp, input) --- 4719,4729 ---- BUILT_IN_FUNCTION(function_getlogin, input) { #ifdef HAVE_GETLOGIN ! char *retval = getlogin(); #else ! char *retval = getenv("LOGNAME"); #endif + RETURN_STR(retval); } BUILT_IN_FUNCTION(function_getpgrp, input) *************** *** 4883,4890 **** BUILT_IN_FUNCTION(function_rest, input) { int start = 1; ! if (my_atol(input)) GET_INT_ARG(start, input); if (start <= 0) --- 4923,4936 ---- BUILT_IN_FUNCTION(function_rest, input) { int start = 1; + char * test_input; ! /* ! * XXX - This is a total hack. I know it. ! */ ! test_input = input; ! parse_number(&test_input); ! if (test_input > input && my_isspace(*test_input)) GET_INT_ARG(start, input); if (start <= 0) *************** *** 5441,5447 **** BUILT_IN_FUNCTION(function_ttyname, input) { ! RETURN_STR(ttyname(0)); } /* --- 5487,5494 ---- BUILT_IN_FUNCTION(function_ttyname, input) { ! char *retval = ttyname(0); ! RETURN_STR(retval); } /* *************** *** 5472,5484 **** /* Submitted by srfrog, August 11, 1999 */ BUILT_IN_FUNCTION(function_urlencode, input) { ! RETURN_STR(urlencode(input)); } /* Submitted by srfrog, August 11, 1999 */ BUILT_IN_FUNCTION(function_urldecode, input) { ! RETURN_STR(urldecode(input)); } BUILT_IN_FUNCTION(function_stat, input) --- 5519,5533 ---- /* Submitted by srfrog, August 11, 1999 */ BUILT_IN_FUNCTION(function_urlencode, input) { ! char *retval = urlencode(input); ! RETURN_STR(retval); } /* Submitted by srfrog, August 11, 1999 */ BUILT_IN_FUNCTION(function_urldecode, input) { ! char *retval = urldecode(input); ! RETURN_STR(retval); } BUILT_IN_FUNCTION(function_stat, input) *************** *** 5548,5559 **** BUILT_IN_FUNCTION(function_getset, input) { ! RETURN_MSTR(make_string_var(input)); } BUILT_IN_FUNCTION(function_builtin, input) { ! RETURN_MSTR(built_in_alias (*input, NULL)); } /* --- 5597,5610 ---- BUILT_IN_FUNCTION(function_getset, input) { ! char *retval = make_string_var(input); ! RETURN_MSTR(retval); } BUILT_IN_FUNCTION(function_builtin, input) { ! char *retval = built_in_alias(*input, NULL); ! RETURN_MSTR(retval); } /*