From: Ari Johnson Date: Tue, 20 Feb 2007 22:11:17 +0000 (+0000) Subject: extract()'s second and third arguments are now optional; default to 1 X-Git-Tag: 0.73~165 X-Git-Url: https://git.theari.com/?a=commitdiff_plain;h=bfaa1575640b2bc2f62e028df4218ded613e6fff;p=cobramush.git extract()'s second and third arguments are now optional; default to 1 --- diff --git a/game/txt/hlp/cobra_func.hlp b/game/txt/hlp/cobra_func.hlp index 4cea943..ac564dd 100644 --- a/game/txt/hlp/cobra_func.hlp +++ b/game/txt/hlp/cobra_func.hlp @@ -1165,10 +1165,13 @@ Returns e to the power of . & EXTRACT() - extract(,,[,]) + extract([,[,[,]]]) This function returns elements of a list, counting - from the element. + from the element. If is not specified, the + default is 1, so extract(list,3) acts like elements(list,3). + If is not specified, the default is the 1, so + extract(list) acts like first(list). For example: think extract(This is a test string,3,2) diff --git a/src/function.c b/src/function.c index c725706..baa03ef 100644 --- a/src/function.c +++ b/src/function.c @@ -362,7 +362,7 @@ FUNTAB flist[] = { {"EVAL", fun_eval, 2, 2, FN_REG}, {"ESCAPE", fun_escape, 1, -1, FN_REG}, {"EXIT", fun_exit, 1, 1, FN_REG}, - {"EXTRACT", fun_extract, 3, 4, FN_REG}, + {"EXTRACT", fun_extract, 1, 4, FN_REG}, {"FILTER", fun_filter, 2, 4, FN_REG}, {"FILTERBOOL", fun_filter, 2, 4, FN_REG}, {"FINDABLE", fun_findable, 2, 2, FN_REG}, diff --git a/src/funlist.c b/src/funlist.c index 9eab2a2..d653c77 100644 --- a/src/funlist.c +++ b/src/funlist.c @@ -1919,8 +1919,8 @@ FUNCTION(fun_wordpos) /* ARGSUSED */ FUNCTION(fun_extract) { - char sep; - int start, len; + char sep = ' '; + int start = 1, len = 1; char *s, *r; if (!is_integer(args[1]) || !is_integer(args[2])) { @@ -1928,9 +1928,22 @@ FUNCTION(fun_extract) return; } s = args[0]; - start = parse_integer(args[1]); - len = parse_integer(args[2]); - if (!delim_check(buff, bp, nargs, args, 4, &sep)) + + if (nargs > 1) { + if (!is_integer(args[1])) { + safe_str(T(e_ints), buff, bp); + return; + } + start = parse_integer(args[1]); + } + if (nargs > 2) { + if (!is_integer(args[2])) { + safe_str(T(e_ints), buff, bp); + return; + } + len = parse_integer(args[2]); + } + if ((nargs > 3) && (!delim_check(buff, bp, nargs, args, 4, &sep))) return; if ((start < 1) || (len < 1))