Add apply()
authorAri Johnson <ari@theari.com>
Tue, 9 Jun 2009 22:44:57 +0000 (22:44 +0000)
committerAri Johnson <ari@theari.com>
Fri, 22 May 2009 15:04:49 +0000 (15:04 +0000)
(cherry picked from commit b4ce97a145d9297e4d0791266e6bf8935510a427)

src/function.c
src/funlist.c
win32/funs.h

index bb3bc75dac82fa53c7dc4fc9018ae8d3570622f6..f978a68dc38ca3fb9b0e66894cdf9c60bd9f6051 100644 (file)
@@ -285,6 +285,7 @@ FUNTAB flist[] = {
   {"ANDPOWERS", fun_andflags, 2, 2, FN_REG},
   {"ANSI", fun_ansi, 2, -2, FN_NOPARSE},
   {"APOSS", fun_aposs, 1, 1, FN_REG},
+  {"APPLY", fun_apply, 1, 3, FN_REG},
   {"ARABIC2ROMAN", fun_arabictoroman, 1, 1, FN_REG},
   {"ART", fun_art, 1, 1, FN_REG},
   {"ATRLOCK", fun_atrlock, 1, 2, FN_REG},
index 4a9dab143baceb51a9f6824e2b5324cfd16ab2ce..f56f215c545f0642fb7e66f2dcb983a98fc3536c 100644 (file)
@@ -3503,3 +3503,33 @@ FUNCTION(fun_regrab)
   if (study)
     mush_free((Malloc_t) study, "pcre.extra");
 }
+
+FUNCTION(fun_apply)
+{
+  char sep;
+  int count;
+  char *arr[10];
+  ufun_attrib ufun;
+  char rbuff[BUFFER_LEN];
+  OOREF_DECL;
+
+  if (!delim_check(buff, bp, nargs, args, 3, &sep))
+    return;
+
+  ENTER_OOREF;
+
+  count = list2arr(arr, 10, args[1], sep);
+
+  if (!fetch_ufun_attrib(args[0], executor, &ufun, 1)) {
+    safe_str(T(ufun.errmess), buff, bp);
+    LEAVE_OOREF;
+    return;
+  }
+
+  call_ufun(&ufun, arr, count, rbuff, executor, enactor, pe_info);
+
+  LEAVE_OOREF;
+
+  safe_str(rbuff, buff, bp);
+}
+
index 5eefb07d4b1bfb04dafc71112751f194c4164149..0948d7eecee2927211a9930edde20e6f5358841f 100644 (file)
@@ -15,6 +15,7 @@ FUNCTION_PROTO(fun_andflags);
 FUNCTION_PROTO(fun_andlflags);
 FUNCTION_PROTO(fun_ansi);
 FUNCTION_PROTO(fun_aposs);
+FUNCTION_PROTO(fun_apply);
 FUNCTION_PROTO(fun_arabictoroman);
 FUNCTION_PROTO(fun_art);
 FUNCTION_PROTO(fun_asin);