From 05459a9a780d5f2eab2c558cac3c8079eb42fa76 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net>
Date: Thu, 9 Apr 1998 13:47:21 -0700
Subject: [PATCH] combine_path() now take any amount of arguments

Rev: src/builtin_functions.c:1.90
---
 src/builtin_functions.c | 38 ++++++++++++++++++++++++++------------
 1 file changed, 26 insertions(+), 12 deletions(-)

diff --git a/src/builtin_functions.c b/src/builtin_functions.c
index 9d78cce48b..0bdd2fc24c 100644
--- a/src/builtin_functions.c
+++ b/src/builtin_functions.c
@@ -4,7 +4,7 @@
 ||| See the files COPYING and DISCLAIMER for more information.
 \*/
 #include "global.h"
-RCSID("$Id: builtin_functions.c,v 1.89 1998/04/01 14:25:51 grubba Exp $");
+RCSID("$Id: builtin_functions.c,v 1.90 1998/04/09 20:47:21 hubbe Exp $");
 #include "interpret.h"
 #include "svalue.h"
 #include "pike_macros.h"
@@ -491,23 +491,37 @@ static char *combine_path(char *cwd,char *file)
 
 void f_combine_path(INT32 args)
 {
-  char *path;
-  if(args<2)
+  char *path=0;
+  int e,dofree=0;
+  struct pike_string *ret;
+
+  if(args<1)
     error("Too few arguments to combine_path.\n");
 
   if(sp[-args].type != T_STRING)
     error("Bad argument 1 to combine_path.\n");
 
-  if(sp[1-args].type != T_STRING)
-    error("Bad argument 2 to combine_path.\n");
+  path=sp[-args].u.string->str;
 
-  path=combine_path(sp[-args].u.string->str,sp[1-args].u.string->str);
-  pop_n_elems(args);
+  for(e=1;e<args;e++)
+  {
+    char *newpath;
+    if(sp[e-args].type != T_STRING)
+    {
+      if(dofree) free(path);
+      error("Bad argument %d to combine_path.\n",e);
+    }
 
-  sp->u.string=make_shared_string(path);
-  sp->type=T_STRING;
-  sp++;
-  free(path);
+    newpath=combine_path(path,sp[e-args].u.string->str);
+    if(dofree) free(path);
+    path=newpath;
+    dofree=1;
+  }
+    
+  ret=make_shared_string(path);
+  if(dofree) free(path);
+  pop_n_elems(args);
+  push_string(ret);
 }
 
 void f_function_object(INT32 args)
@@ -2524,7 +2538,7 @@ void init_builtin_efuns(void)
   add_efun("backtrace",f_backtrace,"function(:array(array(function|int|string)))",OPT_EXTERNAL_DEPEND);
 
   add_efun("column",f_column,"function(array,mixed:array)",0);
-  add_efun("combine_path",f_combine_path,"function(string,string:string)",0);
+  add_efun("combine_path",f_combine_path,"function(string...:string)",0);
   add_efun("compile",f_compile,"function(string:program)",OPT_EXTERNAL_DEPEND);
   add_efun("copy_value",f_copy_value,"function(1=mixed:1)",0);
   add_efun("crypt",f_crypt,"function(string:string)|function(string,string:int)",OPT_EXTERNAL_DEPEND);
-- 
GitLab