From: Rick L Bird Date: Thu, 5 May 2011 23:47:46 +0000 (-0400) Subject: PennMUSH 1.8.3p11 X-Git-Url: https://git.theari.com/?a=commitdiff_plain;h=7fb65d98e6a112c10557fb3d76ba7e6b0d60505a;p=cobramush.git PennMUSH 1.8.3p11 Author: captdeaf@gmail.com Date: Mon Nov 23 23:25:48 2009 +0000 Added a argument to lnum() Fixes #138 --- diff --git a/src/function.c b/src/function.c index cc16877..21c3840 100644 --- a/src/function.c +++ b/src/function.c @@ -502,7 +502,7 @@ FUNTAB flist[] = { {"LLOCKFLAGS", fun_lockflags, 0, 1, FN_REG}, {"LLOCKS", fun_locks, 1, 1, FN_REG}, {"LMATH", fun_lmath, 2, 3, FN_REG}, - {"LNUM", fun_lnum, 1, 3, FN_REG}, + {"LNUM", fun_lnum, 1, 4, FN_REG}, {"LOC", fun_loc, 1, 1, FN_REG}, {"LOCTREE", fun_loctree, 1, 1, FN_REG}, {"LOCALIZE", fun_localize, 1, 1, FN_NOPARSE}, diff --git a/src/funlist.c b/src/funlist.c index 4d6668e..907f871 100644 --- a/src/funlist.c +++ b/src/funlist.c @@ -1279,12 +1279,14 @@ FUNCTION(fun_lnum) NVAL j; NVAL start; NVAL end; - int istart, iend, k; + NVAL step = 1.0; + int istart, iend, k, istep; char const *osep = " "; static NVAL cstart[CACHE_SIZE]; static NVAL cend[CACHE_SIZE]; static char csep[CACHE_SIZE][BUFFER_LEN]; static char cresult[CACHE_SIZE][BUFFER_LEN]; + static int cstep[CACHE_SIZE]; static int cpos; char *cp; @@ -1298,6 +1300,9 @@ FUNCTION(fun_lnum) safe_str(T(e_num), buff, bp); return; } + if (nargs > 3 && is_number(args[3])) { + step = parse_number(args[3]); + } start = end; end = parse_number(args[1]); if ((start == 0) && (end == 0)) { @@ -1322,7 +1327,8 @@ FUNCTION(fun_lnum) osep = args[2]; } for (k = 0; k < CACHE_SIZE; k++) { - if (cstart[k] == start && cend[k] == end && !strcmp(csep[k], osep)) { + if (cstart[k] == start && cend[k] == end && !strcmp(csep[k], osep) && + cstep[k] == step) { safe_str(cresult[k], buff, bp); return; } @@ -1335,16 +1341,17 @@ FUNCTION(fun_lnum) istart = (int) start; iend = (int) end; - if (istart == start && iend == end) { + istep = (int) step; + if (istart == start && iend == end && istep == step) { safe_integer(istart, cresult[cpos], &cp); if (istart <= iend) { - for (k = istart + 1; k <= iend; k++) { + for (k = istart + istep; k <= iend; k += istep) { safe_str(osep, cresult[cpos], &cp); if (safe_integer(k, cresult[cpos], &cp)) break; } } else { - for (k = istart - 1; k >= iend; k--) { + for (k = istart - istep; k >= iend; k -= istep) { safe_str(osep, cresult[cpos], &cp); if (safe_integer(k, cresult[cpos], &cp)) break; @@ -1353,13 +1360,13 @@ FUNCTION(fun_lnum) } else { safe_number(start, cresult[cpos], &cp); if (start <= end) { - for (j = start + 1; j <= end; j++) { + for (j = start + step; j <= end; j += step) { safe_str(osep, cresult[cpos], &cp); if (safe_number(j, cresult[cpos], &cp)) break; } } else { - for (j = start - 1; j >= end; j--) { + for (j = start - step; j >= end; j -= step) { safe_str(osep, cresult[cpos], &cp); if (safe_number(j, cresult[cpos], &cp)) break;